Skip to content

Commit a03c04e

Browse files
SonickidnextgenSonickidnextgen
authored andcommitted
Added options for custom configurations.
1 parent 0da80ca commit a03c04e

File tree

4 files changed

+103
-21
lines changed

4 files changed

+103
-21
lines changed

IOSync/Info.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<ImportGroup Label="PropertySheets" />
44
<PropertyGroup Label="UserMacros">
5-
<IOSync_Version>1.0.1</IOSync_Version>
5+
<IOSync_Version>1.0.2</IOSync_Version>
66
</PropertyGroup>
77
<PropertyGroup />
88
<ItemDefinitionGroup />

IOSync/src/iosync.cpp

Lines changed: 95 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,7 @@ namespace iosync
10321032
// Application:
10331033
const wstring iosync_application::applicationConfiguration::APPLICATION_MODE = L"mode";
10341034
const wstring iosync_application::applicationConfiguration::APPLICATION_USECMD = L"force_cmd";
1035+
const wstring iosync_application::applicationConfiguration::APPLICATION_CONFIG = L"config";
10351036

10361037
// Devices:
10371038
const wstring iosync_application::applicationConfiguration::DEVICES_KEYBOARD = L"keyboard";
@@ -1135,19 +1136,28 @@ namespace iosync
11351136
{
11361137
auto application = applicationIterator->second;
11371138

1139+
// Check if we're being redirected somewhere else:
1140+
auto redirectIterator = application.find(APPLICATION_CONFIG);
1141+
1142+
if (redirectIterator != application.end())
11381143
{
1139-
auto cmdIterator = application.find(APPLICATION_USECMD);
1144+
// Load the redirection-file, instead.
1145+
load(redirectIterator->second);
11401146

1141-
if (cmdIterator != application.end())
1142-
{
1143-
useCmd = wstrEnabled(cmdIterator->second);
1147+
return;
1148+
}
1149+
1150+
auto cmdIterator = application.find(APPLICATION_USECMD);
11441151

1145-
// Check if we're forcing command-line input:
1146-
if (useCmd)
1147-
{
1148-
// Don't bother reading further, we don't need to.
1149-
return;
1150-
}
1152+
if (cmdIterator != application.end())
1153+
{
1154+
useCmd = wstrEnabled(cmdIterator->second);
1155+
1156+
// Check if we're forcing command-line input:
1157+
if (useCmd)
1158+
{
1159+
// Don't bother reading further, we don't need to.
1160+
return;
11511161
}
11521162
}
11531163

@@ -1680,6 +1690,9 @@ namespace iosync
16801690
// This acts as the default 'execute' implementation.
16811691
int iosync_application::execute()
16821692
{
1693+
// Namespace(s):
1694+
using namespace INI;
1695+
16831696
// Local variable(s):
16841697
auto argCount = args.size();
16851698

@@ -1729,13 +1742,77 @@ namespace iosync
17291742
#endif
17301743
#endif
17311744
#ifdef IOSYNC_CONSOLE_INPUT
1732-
bool logChoices = false;
1745+
wstring output_file = applicationConfiguration::DEFAULT_PATH;
17331746

1734-
#ifndef IOSYNC_FAST_TESTMODE
1735-
cout << "Unable to load configuration; would you like to log new settings? (Y/N): "; logChoices = userBoolean(); // cout << endl;
1736-
#endif
1747+
cout << "Unable to load configuration: ";
1748+
1749+
do
1750+
{
1751+
bool logChoices = false;
1752+
bool newFile = false;
1753+
1754+
#ifndef IOSYNC_FAST_TESTMODE
1755+
cout << "Would you like to specify a custom configuration-file? (Y/N): "; newFile = userBoolean();
1756+
1757+
if (!newFile)
1758+
{
1759+
cout << "Would you like to log new settings? (Y/N): "; logChoices = userBoolean();
1760+
}
1761+
else
1762+
{
1763+
cout << "Please specifiy a configuration file: ";
1764+
wcin >> output_file; // cout << endl;
1765+
1766+
// Local variable(s):
1767+
bool loadingWorked = false;
1768+
applicationConfiguration configuration;
1769+
1770+
try
1771+
{
1772+
configuration.load(output_file);
1773+
1774+
loadingWorked = true;
1775+
}
1776+
catch (exception&)
1777+
{
1778+
cout << "Unable to load custom configuration file." << endl;
1779+
}
1780+
1781+
cout << "Would you like this to be your default file? (Y/N): "; logChoices = userBoolean();
1782+
1783+
if (logChoices)
1784+
{
1785+
// If the user used the default file-name, don't bother redirecting.
1786+
if (output_file != applicationConfiguration::DEFAULT_PATH)
1787+
{
1788+
INIVariables<wstring> redirectionRep;
1789+
1790+
auto& application = redirectionRep[applicationConfiguration::APPLICATION_SECTION] = INISection<wstring>();
1791+
1792+
application[applicationConfiguration::APPLICATION_CONFIG] = output_file;
1793+
1794+
save(applicationConfiguration::DEFAULT_PATH, redirectionRep);
1795+
}
1796+
}
1797+
else if (loadingWorked)
1798+
{
1799+
return applyConfiguration(configuration);
1800+
}
1801+
else
1802+
{
1803+
wcout << L"Would you like to log to this file? (\"" << output_file << L"\", Y/N): "; logChoices = userBoolean();
1804+
1805+
if (!logChoices)
1806+
{
1807+
// Try asking the user again.
1808+
continue;
1809+
}
1810+
}
1811+
}
1812+
#endif
17371813

1738-
return applyCommandlineConfiguration(applicationConfiguration(mode), logChoices);
1814+
return applyCommandlineConfiguration(applicationConfiguration(mode), logChoices, output_file);
1815+
} while (true);
17391816
#endif
17401817
#ifndef IOSYNC_FAST_TESTMODE
17411818
}
@@ -1892,7 +1969,7 @@ namespace iosync
18921969
return -1;
18931970
}
18941971

1895-
int iosync_application::applyCommandlineConfiguration(applicationConfiguration& configuration, bool logChoices)
1972+
int iosync_application::applyCommandlineConfiguration(applicationConfiguration& configuration, const bool logChoices, const wstring& output_file)
18961973
{
18971974
configuration.remoteAddress.port = DEFAULT_PORT;
18981975

@@ -1922,7 +1999,7 @@ namespace iosync
19221999

19232000
if (logChoices)
19242001
{
1925-
configuration.save();
2002+
configuration.save(output_file);
19262003
}
19272004

19282005
//clearConsole();
@@ -1959,7 +2036,7 @@ namespace iosync
19592036

19602037
if (logChoices)
19612038
{
1962-
configuration.save();
2039+
configuration.save(output_file);
19632040
}
19642041

19652042
//clearConsole();

IOSync/src/iosync.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,9 @@ namespace iosync
749749
static const wstring APPLICATION_MODE;
750750
static const wstring APPLICATION_USECMD;
751751

752+
// This is used to redirect to another configuration-file.
753+
static const wstring APPLICATION_CONFIG;
754+
752755
// Devices:
753756
static const wstring DEVICES_KEYBOARD;
754757
static const wstring DEVICES_GAMEPADS;
@@ -960,7 +963,7 @@ namespace iosync
960963
// If the 'logChoices' argument is set to 'true', this may write to the disk.
961964
// The 'configuration' argument should be a valid container
962965
// used to output the settings provided by the user.
963-
int applyCommandlineConfiguration(applicationConfiguration& configuration, bool logChoices=false);
966+
int applyCommandlineConfiguration(applicationConfiguration& configuration, const bool logChoices=false, const wstring& output_file=wstring());
964967

965968
void onCreate(applicationMode mode=MODE_SERVER);
966969
void onClose();

XInput_Injection_DLL/XInput_Injector.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
// Other:
1414
//#define DLLExport // __declspec( dllexport )
1515

16+
//#define DLL_DEBUG
17+
#define DLL_CONFIRMATION_MESSAGE
18+
1619
// Includes:
17-
#include "settings.h"
1820

1921
// Windows-specific:
2022
#include <windows.h>

0 commit comments

Comments
 (0)