move SettingsHandler to Common lib

This commit is contained in:
Shawn Hoffman 2012-02-09 21:04:07 -08:00
parent c8129bc802
commit ac0883044e
9 changed files with 96 additions and 97 deletions

View File

@ -15,6 +15,7 @@ set(SRCS Src/ABI.cpp
Src/Misc.cpp
Src/MsgHandler.cpp
Src/NandPaths.cpp
Src/SettingsHandler.cpp
Src/SDCardUtil.cpp
Src/StringUtil.cpp
Src/SymbolDB.cpp

View File

@ -195,6 +195,7 @@
<ClCompile Include="Src\MsgHandler.cpp" />
<ClCompile Include="Src\NandPaths.cpp" />
<ClCompile Include="Src\SDCardUtil.cpp" />
<ClCompile Include="Src\SettingsHandler.cpp" />
<ClCompile Include="Src\stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
@ -251,6 +252,7 @@
<ClInclude Include="Src\MsgHandler.h" />
<ClInclude Include="Src\NandPaths.h" />
<ClInclude Include="Src\SDCardUtil.h" />
<ClInclude Include="Src\SettingsHandler.h" />
<ClInclude Include="Src\Setup.h" />
<ClInclude Include="Src\stdafx.h" />
<ClInclude Include="Src\StdConditionVariable.h" />

View File

@ -53,6 +53,7 @@
<ClCompile Include="Src\Crypto\sha1.cpp">
<Filter>Crypto</Filter>
</ClCompile>
<ClCompile Include="Src\SettingsHandler.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Src\ABI.h" />
@ -121,6 +122,7 @@
</ClInclude>
<ClInclude Include="Src\StdMutex.h" />
<ClInclude Include="Src\StdConditionVariable.h" />
<ClInclude Include="Src\SettingsHandler.h" />
</ItemGroup>
<ItemGroup>
<None Include="CMakeLists.txt" />

View File

@ -42,42 +42,46 @@ const u8* SettingsHandler::GetData() const
return m_buffer;
}
const std::string SettingsHandler::GetValue(std::string key)
const std::string SettingsHandler::GetValue(const std::string key)
{
std::string delim = std::string("\r\n");
std::string toFind = delim + key + "=";
size_t found = decoded.find(toFind);
if (found!=std::string::npos){
size_t delimFound = decoded.find(delim, found+toFind.length());
if (delimFound == std::string::npos)
delimFound = decoded.length()-1;
return decoded.substr(found+toFind.length(), delimFound - (found+toFind.length()));
}else{
if (found != decoded.npos)
{
size_t delimFound = decoded.find(delim, found + toFind.length());
if (delimFound == decoded.npos)
delimFound = decoded.length() - 1;
return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length()));
}
else
{
toFind = key + "=";
size_t found = decoded.find(toFind);
if (found==0){
size_t delimFound = decoded.find(delim, found+toFind.length());
if (delimFound == std::string::npos)
delimFound = decoded.length()-1;
return decoded.substr(found+toFind.length(), delimFound - (found+toFind.length()));
if (found == 0)
{
size_t delimFound = decoded.find(delim, found + toFind.length());
if (delimFound == decoded.npos)
delimFound = decoded.length() - 1;
return decoded.substr(found + toFind.length(), delimFound - (found + toFind.length()));
}
}
return "";
}
void SettingsHandler::Decrypt()
{
const u8 *str = m_buffer;
while(*str != 0){
while (*str != 0)
{
if (m_position >= SETTINGS_SIZE)
return;
decoded.push_back((u8)(m_buffer[m_position] ^ m_key));
m_position++;
str++;
m_key = ((m_key >> 31) | (m_key << 1));
m_key = (m_key >> 31) | (m_key << 1);
}
}
@ -116,21 +120,21 @@ void SettingsHandler::WriteByte(u8 b)
m_buffer[m_position] = b ^ m_key;
m_position++;
m_key = ((m_key >> 31) | (m_key << 1));
m_key = (m_key >> 31) | (m_key << 1);
}
std::string SettingsHandler::generateSerialNumber()
const std::string SettingsHandler::generateSerialNumber()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [12];
char serialNumber [12];
tm *timeinfo;
char buffer[12];
char serialNumber[12];
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime (buffer,11,"%j%H%M%S",timeinfo);
time(&rawtime);
timeinfo = localtime(&rawtime);
strftime(buffer, 11, "%j%H%M%S", timeinfo);
snprintf(serialNumber,11, "%s%i", buffer, (Common::Timer::GetTimeMs()>>1)&0xF);
snprintf(serialNumber, 11, "%s%i", buffer, (Common::Timer::GetTimeMs() >> 1) & 0xF);
serialNumber[10] = 0;
return std::string(serialNumber);
}

View File

@ -17,28 +17,31 @@
// Thanks to Treeki for writing the original class - 29/01/2012
#ifndef _SETTINGS_HANDLER_H
#define _SETTINGS_HANDLER_H
#pragma once
#include <string>
#include "Common.h"
#include "../CoreParameter.h"
#define SETTINGS_SIZE 0x100
class SettingsHandler
{
public:
SettingsHandler();
enum
{
SETTINGS_SIZE = 0x100
};
void AddSetting(const char *key, const char *value);
const u8 *GetData() const;
const std::string GetValue(std::string key);
const std::string GetValue(const std::string key);
void Decrypt();
void Reset();
std::string generateSerialNumber();
const std::string generateSerialNumber();
private:
void WriteByte(u8 b);
@ -46,5 +49,3 @@ private:
u32 m_position, m_key;
std::string decoded;
};
#endif

View File

@ -203,7 +203,6 @@
<ClCompile Include="Src\Boot\Boot_ELF.cpp" />
<ClCompile Include="Src\Boot\Boot_WiiWAD.cpp" />
<ClCompile Include="Src\Boot\ElfReader.cpp" />
<ClCompile Include="Src\Boot\SettingsHandler.cpp" />
<ClCompile Include="Src\ConfigManager.cpp" />
<ClCompile Include="Src\Console.cpp" />
<ClCompile Include="Src\Core.cpp" />
@ -408,7 +407,6 @@
<ClInclude Include="Src\Boot\Boot_ELF.h" />
<ClInclude Include="Src\Boot\ElfReader.h" />
<ClInclude Include="Src\Boot\ElfTypes.h" />
<ClInclude Include="Src\Boot\SettingsHandler.h" />
<ClInclude Include="Src\ConfigManager.h" />
<ClInclude Include="Src\Console.h" />
<ClInclude Include="Src\Core.h" />

View File

@ -559,9 +559,6 @@
<ClCompile Include="Src\HW\GCMemcard.cpp">
<Filter>HW %28Flipper/Hollywood%29\GCMemcard</Filter>
</ClCompile>
<ClCompile Include="Src\Boot\SettingsHandler.cpp">
<Filter>Boot</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Src\ConfigManager.h" />
@ -1045,9 +1042,6 @@
<ClInclude Include="Src\IPC_HLE\fakepoll.h">
<Filter>IPC HLE %28IOS/Starlet%29\Net</Filter>
</ClInclude>
<ClInclude Include="Src\Boot\SettingsHandler.h">
<Filter>Boot</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="CMakeLists.txt" />

View File

@ -177,11 +177,7 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
{
INFO_LOG(BOOT, "Setup Wii Memory...");
// Write the 256 byte setting.txt to memory. This may not be needed as
// most or all games read the setting.txt file from
// \title\00000001\00000002\data\setting.txt directly after the read the
// SYSCONF file. The games also read it to 0x3800, what is a little strange
// however is that it only reads the first 100 bytes of it.
// Write the 256 byte setting.txt to memory.
std::string settings_Filename(Common::GetTitleDataPath(TITLEID_SYSMENU) + WII_SETTING);
std::string area, model, code, video, game;
@ -217,13 +213,13 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
code = "L" + area.substr(0,1);
game = area.substr(0,2);
SettingsHandler gen;
std::string serno = "";
if (File::Exists(settings_Filename))
{
File::IOFile settingsFileHandle(settings_Filename, "rb");
if(settingsFileHandle.ReadBytes((void*)gen.GetData(), SETTINGS_SIZE)){
if (settingsFileHandle.ReadBytes((void*)gen.GetData(), SettingsHandler::SETTINGS_SIZE))
{
gen.Decrypt();
serno = gen.GetValue("SERNO");
gen.Reset();
@ -231,10 +227,13 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
File::Delete(settings_Filename);
}
if(serno.empty() || serno == "000000000"){
if (serno.empty() || serno == "000000000")
{
serno = gen.generateSerialNumber();
INFO_LOG(BOOT, "No previous serial number found, generated one instead: %s", serno.c_str());
}else{
}
else
{
INFO_LOG(BOOT, "Using serial number: %s", serno.c_str());
}
@ -253,12 +252,12 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
{
File::IOFile settingsFileHandle(settings_Filename, "wb");
if (!settingsFileHandle.WriteBytes(gen.GetData(), SETTINGS_SIZE))
if (!settingsFileHandle.WriteBytes(gen.GetData(), SettingsHandler::SETTINGS_SIZE))
{
PanicAlertT("SetupWiiMem: Cant create setting file");
return false;
}
Memory::WriteBigEData(gen.GetData(), 0x3800, SETTINGS_SIZE);
Memory::WriteBigEData(gen.GetData(), 0x3800, SettingsHandler::SETTINGS_SIZE);
}
/*

View File

@ -201,8 +201,6 @@ public:
// TODO Writes stuff to /shared2/nwc24/misc.bin
u32 update_misc = 0;
static bool init = false;
switch (Parameter)
{
case IOCTL_NW24_GET_UNIVERSAL_TIME: