-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ferris
committed
May 18, 2013
1 parent
8ac0ad6
commit 87f9719
Showing
5 changed files
with
101 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include "Config.h" | ||
|
||
Config::Config(const String& fileName) | ||
{ | ||
this->fileName = fileName; | ||
AudioEnabled = true; | ||
AudioLatencyIndex = 2; | ||
VideoZoomIndex = 1; | ||
SystemSpeedIndex = 4; | ||
|
||
try | ||
{ | ||
auto input = File::ReadAllLines(fileName); | ||
|
||
int value; | ||
if (tryGetValue(input, "AudioEnabled", value)) AudioEnabled = value != 0; | ||
if (tryGetValue(input, "AudioLatencyIndex", value)) AudioLatencyIndex = value; | ||
if (tryGetValue(input, "VideoZoomIndex", value)) VideoZoomIndex = value; | ||
if (tryGetValue(input, "SystemSpeedIndex", value)) SystemSpeedIndex = value; | ||
} | ||
catch (...) { } | ||
} | ||
|
||
void Config::Save() | ||
{ | ||
String output; | ||
|
||
output += String("AudioEnabled:") + AudioEnabled + "\n"; | ||
output += String("AudioLatencyIndex:") + AudioLatencyIndex + "\n"; | ||
output += String("VideoZoomIndex:") + VideoZoomIndex + "\n"; | ||
output += String("SystemSpeedIndex:") + SystemSpeedIndex + "\n"; | ||
|
||
try | ||
{ | ||
File::WriteAllText(fileName, output); | ||
} | ||
catch (...) { } | ||
} | ||
|
||
bool Config::tryGetValue(const List<String>& input, const String& name, int& value) | ||
{ | ||
for (int i = 0; i < input.Count(); i++) | ||
{ | ||
auto parts = input[i].Split(':'); | ||
if (parts.Count() == 2 && parts[0] == name) | ||
{ | ||
if (parts[1].TryParseInt(value)) return true; | ||
} | ||
} | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef __CONFIG_H__ | ||
#define __CONFIG_H__ | ||
|
||
#include "Common.h" | ||
|
||
class Config | ||
{ | ||
public: | ||
Config(const String& fileName); | ||
|
||
void Save(); | ||
|
||
bool AudioEnabled; | ||
int AudioLatencyIndex; | ||
int VideoZoomIndex; | ||
int SystemSpeedIndex; | ||
|
||
private: | ||
static bool tryGetValue(const List<String>& input, const String& name, int& value); | ||
|
||
String fileName; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters