Skip to content

Commit 79e2dfe

Browse files
committed
Add the command line parsing, some app icon and the hide option
1 parent 157a7cf commit 79e2dfe

File tree

9 files changed

+107
-17
lines changed

9 files changed

+107
-17
lines changed

LaunchBounce/LaunchBounce.vcxproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
<ItemGroup>
3636
<ResourceCompile Include="Source\LaunchBounce.rc" />
3737
</ItemGroup>
38+
<ItemGroup>
39+
<Image Include="Source\LaunchBounce.ico" />
40+
</ItemGroup>
3841
<PropertyGroup Label="Globals">
3942
<VCProjectVersion>17.0</VCProjectVersion>
4043
<Keyword>Win32Proj</Keyword>
@@ -113,7 +116,7 @@
113116
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
114117
</ClCompile>
115118
<Link>
116-
<SubSystem>Console</SubSystem>
119+
<SubSystem>Windows</SubSystem>
117120
<GenerateDebugInformation>true</GenerateDebugInformation>
118121
</Link>
119122
</ItemDefinitionGroup>
@@ -129,7 +132,7 @@
129132
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
130133
</ClCompile>
131134
<Link>
132-
<SubSystem>Console</SubSystem>
135+
<SubSystem>Windows</SubSystem>
133136
<EnableCOMDATFolding>true</EnableCOMDATFolding>
134137
<OptimizeReferences>true</OptimizeReferences>
135138
<GenerateDebugInformation>true</GenerateDebugInformation>
@@ -145,7 +148,7 @@
145148
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
146149
</ClCompile>
147150
<Link>
148-
<SubSystem>Console</SubSystem>
151+
<SubSystem>Windows</SubSystem>
149152
<GenerateDebugInformation>true</GenerateDebugInformation>
150153
</Link>
151154
</ItemDefinitionGroup>
@@ -161,7 +164,7 @@
161164
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
162165
</ClCompile>
163166
<Link>
164-
<SubSystem>Console</SubSystem>
167+
<SubSystem>Windows</SubSystem>
165168
<EnableCOMDATFolding>true</EnableCOMDATFolding>
166169
<OptimizeReferences>true</OptimizeReferences>
167170
<GenerateDebugInformation>true</GenerateDebugInformation>

LaunchBounce/LaunchBounce.vcxproj.filters

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,9 @@
5353
<Filter>Resource Files</Filter>
5454
</ResourceCompile>
5555
</ItemGroup>
56+
<ItemGroup>
57+
<Image Include="Source\LaunchBounce.ico">
58+
<Filter>Resource Files</Filter>
59+
</Image>
60+
</ItemGroup>
5661
</Project>

LaunchBounce/Source/Configuration.cpp

Lines changed: 72 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,81 @@
1919

2020
using Therena::LaunchBounce::Configuration;
2121

22-
void Configuration::Initialize(int argc, wchar_t* argv[])
22+
void Configuration::Initialize()
2323
{
24-
if (0 == argc || argc % 2 == 0)
25-
{
26-
return;
27-
}
24+
const auto commandLineString = GetCommandLine();
25+
const auto commandLine = ParseCommandLine(commandLineString);
2826

29-
for (auto i = 1; i < argc; i = i + 2)
27+
for (const auto& param : commandLine)
3028
{
3129
auto type = ParameterType::Unknown;
32-
const auto result = ConvertParameterType(argv[i], type);
30+
const auto result = ConvertParameterType(param.first, type);
3331
if (result)
3432
{
35-
m_Parameters[type] = argv[i + 1];
33+
m_Parameters[type] = param.second;
3634
}
3735
}
3836
}
3937

38+
std::vector<std::pair<std::wstring, std::wstring>> Configuration::ParseCommandLine(const std::wstring& commandLine)
39+
{
40+
std::vector<std::pair<std::wstring, std::wstring>> params;
41+
std::wistringstream iss(commandLine);
42+
std::wstring token;
43+
std::wstring key;
44+
std::wstring value;
45+
46+
bool isFirstToken = true;
47+
bool isQuotedValue = false;
48+
while (iss >> token)
49+
{
50+
if (isFirstToken)
51+
{
52+
isFirstToken = false;
53+
continue;
54+
}
55+
56+
if (isQuotedValue)
57+
{
58+
if (token.back() == L'"')
59+
{
60+
value += L" " + token.substr(0, token.length() - 1);
61+
isQuotedValue = false;
62+
params.push_back({ key, value });
63+
value.clear();
64+
}
65+
else
66+
{
67+
value += L" " + token;
68+
}
69+
}
70+
else if (token.front() == L'"')
71+
{
72+
value = token.substr(1);
73+
if (token.back() != L'"')
74+
{
75+
isQuotedValue = true;
76+
}
77+
else
78+
{
79+
value.pop_back();
80+
params.push_back({ key, value });
81+
value.clear();
82+
}
83+
}
84+
else if (token.front() == L'-' && !isQuotedValue)
85+
{
86+
key = token;
87+
}
88+
else
89+
{
90+
params.push_back({ key, token });
91+
}
92+
}
93+
94+
return params;
95+
}
96+
4097
bool Configuration::GetParameter(ParameterType type, std::wstring& parameter)
4198
{
4299
if (m_Parameters.end() == m_Parameters.find(type))
@@ -63,6 +120,13 @@ bool Configuration::ConvertParameterType(const std::wstring& parameter, Paramete
63120
return true;
64121
}
65122

123+
124+
if (std::wstring::npos != parameter.find(L"Hide"))
125+
{
126+
type = ParameterType::Hide;
127+
return true;
128+
}
129+
66130
return false;
67131
}
68132

LaunchBounce/Source/Configuration.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,25 @@ namespace Therena::LaunchBounce
2525
public:
2626
Configuration() = delete;
2727

28-
static void Initialize(int argc, wchar_t* argv[]);
28+
static void Initialize();
2929

3030
static std::filesystem::path GetAppPath();
3131

3232
enum class ParameterType
3333
{
3434
Unknown,
3535
Process,
36-
Parameter
36+
Parameter,
37+
Hide
3738
};
3839

3940
static bool GetParameter(ParameterType type, std::wstring& parameter);
4041

4142
private:
4243
static bool ConvertParameterType(const std::wstring& parameter, ParameterType& type);
4344

45+
static std::vector<std::pair<std::wstring, std::wstring>> ParseCommandLine(const std::wstring& commandLine);
46+
4447
private:
4548
inline static std::map<ParameterType, std::wstring> m_Parameters{};
4649
};

LaunchBounce/Source/LaunchBounce.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ using Therena::LaunchBounce::Logger;
2222
using Therena::LaunchBounce::Process;
2323
using Therena::LaunchBounce::Configuration;
2424

25-
int wmain(int argc, wchar_t* argv[])
25+
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, PSTR cmdline, int cmdshow)
2626
{
27-
Configuration::Initialize(argc, argv);
27+
UNREFERENCED_PARAMETER(hInst);
28+
UNREFERENCED_PARAMETER(hInstPrev);
29+
UNREFERENCED_PARAMETER(cmdline);
30+
UNREFERENCED_PARAMETER(cmdshow);
31+
32+
Configuration::Initialize();
2833

2934
Logger::Info(L"##################################################################################");
3035
Logger::Info(L"Execute launch bounce");
160 KB
Binary file not shown.
558 Bytes
Binary file not shown.

LaunchBounce/Source/Process.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ int Process::Launch()
180180
startupInfo.hStdError = errorPipe->GetWrite();
181181
startupInfo.dwFlags |= STARTF_USESTDHANDLES;
182182

183+
std::wstring hide;
184+
const auto hideResult = Configuration::GetParameter(Configuration::ParameterType::Hide, hide);
185+
if (hideResult)
186+
{
187+
startupInfo.dwFlags |= STARTF_USESHOWWINDOW;
188+
startupInfo.wShowWindow = SW_HIDE;
189+
}
190+
183191
PROCESS_INFORMATION processInformation{};
184192

185193
const auto processCreation = CreateProcess(nullptr,

LaunchBounce/Source/resource.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//{{NO_DEPENDENCIES}}
22
// Microsoft Visual C++ generated include file.
33
// Used by LaunchBounce.rc
4+
//
5+
#define IDI_ICON1 102
46

57
// Next default values for new objects
68
//
79
#ifdef APSTUDIO_INVOKED
810
#ifndef APSTUDIO_READONLY_SYMBOLS
9-
#define _APS_NEXT_RESOURCE_VALUE 101
11+
#define _APS_NEXT_RESOURCE_VALUE 103
1012
#define _APS_NEXT_COMMAND_VALUE 40001
1113
#define _APS_NEXT_CONTROL_VALUE 1001
1214
#define _APS_NEXT_SYMED_VALUE 101

0 commit comments

Comments
 (0)