Skip to content

Commit 44e1483

Browse files
authored
Merge pull request #111 from Microsoft/develop
Create new release
2 parents 5fa61e8 + 783457e commit 44e1483

20 files changed

+731
-58
lines changed

src/vswhere.lib/Formatter.cpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void Formatter::WriteInternal(_In_ const CommandArgs& args, _In_ Console& consol
148148

149149
StartObject(console);
150150

151-
const auto& specified = args.get_Property();
151+
wstring specified = args.get_Property();
152152
variant_t vtValue;
153153
bool found = false;
154154

@@ -169,6 +169,31 @@ void Formatter::WriteInternal(_In_ const CommandArgs& args, _In_ Console& consol
169169
if (specified.empty() || !found)
170170
{
171171
found = WriteProperties(args, console, pInstance);
172+
173+
// Output catalog information.
174+
if (specified.empty() || !found)
175+
{
176+
ISetupInstanceCatalogPtr instanceCatalog;
177+
178+
auto hr = pInstance->QueryInterface(&instanceCatalog);
179+
if (SUCCEEDED(hr))
180+
{
181+
ISetupPropertyStorePtr store;
182+
183+
hr = instanceCatalog->GetCatalogInfo(&store);
184+
if (SUCCEEDED(hr) && !!store)
185+
{
186+
wstring name(L"catalog");
187+
StartObject(console, name);
188+
189+
found = WriteProperties(args, console, store, name);
190+
191+
EndObject(console);
192+
}
193+
}
194+
}
195+
196+
// Output custom properties.
172197
if (specified.empty() || !found)
173198
{
174199
ISetupInstance2Ptr instance2;
@@ -184,7 +209,7 @@ void Formatter::WriteInternal(_In_ const CommandArgs& args, _In_ Console& consol
184209
wstring name(L"properties");
185210
StartObject(console, name);
186211

187-
WriteProperties(args, console, store, name);
212+
found = WriteProperties(args, console, store, name);
188213

189214
EndObject(console);
190215
}
@@ -243,6 +268,8 @@ bool Formatter::WriteProperties(_In_ const CommandArgs& args, _In_ Console& cons
243268
{
244269
_ASSERTE(pProperties);
245270

271+
static ci_less less;
272+
246273
LPSAFEARRAY psaNames = NULL;
247274
auto found = false;
248275

@@ -269,14 +296,25 @@ bool Formatter::WriteProperties(_In_ const CommandArgs& args, _In_ Console& cons
269296
}
270297

271298
SafeArray<BSTR> saNames(psaNames);
272-
for (const auto& bstrName : saNames.Elements())
299+
300+
auto elems = saNames.Elements();
301+
sort(elems.begin(), elems.end(), less);
302+
303+
for (const auto& bstrName : elems)
273304
{
274305
wstring name(bstrName);
275306
if (specified.empty() || (found = s_comparer(name, specified)))
276307
{
277308
variant_t vtValue;
278309

279-
auto it = find_if(m_properties.begin(), m_properties.end(), bind(Formatter::PropertyEqual, name, _1));
310+
auto it = m_properties.end();
311+
312+
// Don't check if we already handled nested properties as top-level properties.
313+
if (prefix.empty())
314+
{
315+
it = find_if(m_properties.begin(), m_properties.end(), bind(Formatter::PropertyEqual, name, _1));
316+
}
317+
280318
if (it == m_properties.end())
281319
{
282320
hr = pProperties->GetValue(bstrName, vtValue.GetAddress());

src/vswhere.lib/JsonFormatter.cpp

Lines changed: 28 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,85 +19,60 @@ void JsonFormatter::StartObject(_In_ Console& console, _In_opt_ const wstring& n
1919
{
2020
if (m_requiresSep.top())
2121
{
22-
console.WriteLine(L",");
22+
console.Write(L",");
2323
}
2424
else
2525
{
2626
// Do not write new line when starting subsequent object immediately after previous object.
2727
if (m_objects.empty())
2828
{
29-
console.WriteLine();
29+
m_requiresSep.top() = true;
3030
}
31-
32-
m_requiresSep.top() = true;
3331
}
3432

3533
m_requiresSep.push(false);
36-
m_objects.push(name);
3734

38-
if (!name.empty())
35+
if (name.empty())
3936
{
40-
console.WriteLine(L"%ls\"%ls\": {", m_padding.c_str(), name.c_str());
37+
m_objects.push(JsonScope(m_padding, JsonScope::empty, true));
38+
m_objects.top().WriteStart(console);
4139
}
4240
else
4341
{
44-
console.WriteLine(L"%ls{", m_padding.c_str());
42+
m_objects.push(JsonScope(m_padding, name));
4543
}
4644

4745
Push();
4846
}
4947

5048
void JsonFormatter::WriteProperty(_In_ Console& console, _In_ const wstring& name, _In_ const wstring& value)
5149
{
52-
if (m_requiresSep.top())
53-
{
54-
console.WriteLine(L",");
55-
}
56-
else
57-
{
58-
m_requiresSep.top() = true;
59-
}
50+
StartProperty(console);
6051

6152
auto escaped = replace_all(value, L"\\", L"\\\\");
62-
console.Write(L"%ls\"%ls\": \"%ls\"", m_padding.c_str(), name.c_str(), escaped.c_str());
53+
console.Write(L"\n%ls\"%ls\": \"%ls\"", m_padding.c_str(), name.c_str(), escaped.c_str());
6354
}
6455

6556
void JsonFormatter::WriteProperty(_In_ Console& console, _In_ const wstring& name, _In_ bool value)
6657
{
67-
if (m_requiresSep.top())
68-
{
69-
console.WriteLine(L",");
70-
}
71-
else
72-
{
73-
m_requiresSep.top() = true;
74-
}
75-
76-
console.Write(L"%ls\"%ls\": %ls", m_padding.c_str(), name.c_str(), (value ? L"true" : L"false"));
58+
StartProperty(console);
59+
console.Write(L"\n%ls\"%ls\": %ls", m_padding.c_str(), name.c_str(), (value ? L"true" : L"false"));
7760
}
7861

7962
void JsonFormatter::WriteProperty(_In_ Console& console, _In_ const wstring& name, _In_ long long value)
8063
{
81-
if (m_requiresSep.top())
82-
{
83-
console.WriteLine(L",");
84-
}
85-
else
86-
{
87-
m_requiresSep.top() = true;
88-
}
89-
90-
console.Write(L"%ls\"%ls\": %d", m_padding.c_str(), name.c_str(), value);
64+
StartProperty(console);
65+
console.Write(L"\n%ls\"%ls\": %d", m_padding.c_str(), name.c_str(), value);
9166
}
9267

9368
void JsonFormatter::EndObject(_In_ Console& console)
9469
{
9570
Pop();
9671

9772
m_requiresSep.pop();
98-
m_objects.pop();
9973

100-
console.Write(L"\n%ls}", m_padding.c_str());
74+
m_objects.top().WriteEnd(console);
75+
m_objects.pop();
10176
}
10277

10378
void JsonFormatter::EndArray(_In_ Console& console)
@@ -123,3 +98,17 @@ wstring JsonFormatter::FormatDate(_In_ const FILETIME& value)
12398
{
12499
return FormatDateISO8601(value);
125100
}
101+
102+
void JsonFormatter::StartProperty(_In_ Console& console)
103+
{
104+
m_objects.top().WriteStart(console);
105+
106+
if (m_requiresSep.top())
107+
{
108+
console.Write(L",");
109+
}
110+
else
111+
{
112+
m_requiresSep.top() = true;
113+
}
114+
}

src/vswhere.lib/JsonFormatter.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ class JsonFormatter :
5959
}
6060
}
6161

62+
void StartProperty(_In_ Console& console);
63+
6264
std::wstring m_padding;
6365
std::stack<bool> m_requiresSep;
64-
std::stack<std::wstring> m_objects;
66+
std::stack<JsonScope> m_objects;
6567
};

src/vswhere.lib/JsonScope.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// <copyright file="JsonScope.cpp" company="Microsoft Corporation">
2+
// Copyright (C) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt in the project root for license information.
4+
// </copyright>
5+
6+
#include "stdafx.h"
7+
8+
using namespace std;
9+
10+
const wstring JsonScope::empty;

src/vswhere.lib/JsonScope.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// <copyright file="JsonScope.h" company="Microsoft Corporation">
2+
// Copyright (C) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt in the project root for license information.
4+
// </copyright>
5+
6+
#pragma once
7+
8+
class JsonScope :
9+
public Scope
10+
{
11+
public:
12+
static const std::wstring empty;
13+
14+
JsonScope(_In_ const std::wstring& padding, _In_ const std::wstring& name = empty, _In_ bool writeEnd = false) :
15+
Scope(padding, name, writeEnd)
16+
{
17+
}
18+
19+
JsonScope(_In_ const JsonScope& obj) :
20+
Scope(obj)
21+
{
22+
}
23+
24+
protected:
25+
void WriteStartImpl(_In_ Console& console) override
26+
{
27+
if (Name().empty())
28+
{
29+
console.Write(L"\n%ls{", Padding().c_str());
30+
}
31+
else
32+
{
33+
console.Write(L"\n%ls\"%ls\": {", Padding().c_str(), Name().c_str());
34+
}
35+
}
36+
37+
void WriteEndImpl(_In_ Console& console) override
38+
{
39+
console.Write(L"\n%ls}", Padding().c_str());
40+
}
41+
};

src/vswhere.lib/SafeArray.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class SafeArray
3030

3131
const std::vector<_Element>& Elements() const
3232
{
33-
return m_interfaces;
33+
return m_elements;
3434
}
3535

3636
private:
@@ -47,7 +47,7 @@ class SafeArray
4747
auto pvData = (_Element*)m_psa->pvData;
4848
auto celt = m_psa->rgsabound[0].cElements;
4949

50-
m_interfaces.assign(pvData, pvData + celt);
50+
m_elements.assign(pvData, pvData + celt);
5151
}
5252
}
5353

@@ -68,5 +68,5 @@ class SafeArray
6868
}
6969

7070
LPSAFEARRAY m_psa;
71-
std::vector<_Element> m_interfaces;
71+
std::vector<_Element> m_elements;
7272
};

src/vswhere.lib/Scope.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// <copyright file="Scope.h" company="Microsoft Corporation">
2+
// Copyright (C) Microsoft Corporation. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt in the project root for license information.
4+
// </copyright>
5+
6+
#pragma once
7+
8+
class Scope
9+
{
10+
public:
11+
Scope(_In_ const std::wstring& padding, _In_ const std::wstring& name, _In_ bool writeEnd = false) :
12+
m_padding(padding),
13+
m_name(name),
14+
m_writeStart(true),
15+
m_writeEnd(writeEnd)
16+
{
17+
}
18+
19+
Scope(_In_ std::wstring& padding, _In_ std::wstring::const_pointer name, _In_ bool writeEnd = false) :
20+
m_padding(padding),
21+
m_name(name),
22+
m_writeStart(true),
23+
m_writeEnd(writeEnd)
24+
{
25+
}
26+
27+
Scope(_In_ const Scope& obj) :
28+
m_padding(obj.m_padding),
29+
m_name(obj.m_name),
30+
m_writeStart(obj.m_writeStart),
31+
m_writeEnd(obj.m_writeEnd)
32+
{
33+
}
34+
35+
void WriteStart(_In_ Console& console)
36+
{
37+
if (m_writeStart)
38+
{
39+
WriteStartImpl(console);
40+
m_writeStart = false;
41+
m_writeEnd = true;
42+
}
43+
}
44+
45+
void WriteEnd(_In_ Console& console)
46+
{
47+
if (m_writeEnd)
48+
{
49+
WriteEndImpl(console);
50+
}
51+
}
52+
53+
protected:
54+
const std::wstring& Padding() const
55+
{
56+
return m_padding;
57+
}
58+
59+
const std::wstring& Name() const
60+
{
61+
return m_name;
62+
}
63+
64+
virtual void WriteStartImpl(_In_ Console& console) = 0;
65+
virtual void WriteEndImpl(_In_ Console& console) = 0;
66+
67+
private:
68+
std::wstring m_padding;
69+
std::wstring m_name;
70+
bool m_writeStart;
71+
bool m_writeEnd;
72+
};

0 commit comments

Comments
 (0)