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/Misc.cpp
Src/MsgHandler.cpp Src/MsgHandler.cpp
Src/NandPaths.cpp Src/NandPaths.cpp
Src/SettingsHandler.cpp
Src/SDCardUtil.cpp Src/SDCardUtil.cpp
Src/StringUtil.cpp Src/StringUtil.cpp
Src/SymbolDB.cpp Src/SymbolDB.cpp

View File

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

View File

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

View File

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

View File

@ -1,50 +1,51 @@
// Copyright (C) 2003 Dolphin Project. // Copyright (C) 2003 Dolphin Project.
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0. // the Free Software Foundation, version 2.0.
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details. // GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program. // A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/ // If not, see http://www.gnu.org/licenses/
// Official SVN repository and contact information can be found at // Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/ // http://code.google.com/p/dolphin-emu/
// Thanks to Treeki for writing the original class - 29/01/2012 // Thanks to Treeki for writing the original class - 29/01/2012
#ifndef _SETTINGS_HANDLER_H #pragma once
#define _SETTINGS_HANDLER_H
#include <string>
#include <string>
#include "Common.h"
#include "Common.h"
#include "../CoreParameter.h" class SettingsHandler
#define SETTINGS_SIZE 0x100 {
public:
class SettingsHandler SettingsHandler();
{
public: enum
SettingsHandler(); {
SETTINGS_SIZE = 0x100
void AddSetting(const char *key, const char *value); };
const u8 *GetData() const; void AddSetting(const char *key, const char *value);
const std::string GetValue(std::string key);
const u8 *GetData() const;
void Decrypt(); const std::string GetValue(const std::string key);
void Reset();
std::string generateSerialNumber(); void Decrypt();
private: void Reset();
void WriteByte(u8 b); const std::string generateSerialNumber();
u8 m_buffer[SETTINGS_SIZE]; private:
u32 m_position, m_key; void WriteByte(u8 b);
std::string decoded;
}; u8 m_buffer[SETTINGS_SIZE];
u32 m_position, m_key;
#endif std::string decoded;
};

View File

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

View File

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

View File

@ -177,11 +177,7 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
{ {
INFO_LOG(BOOT, "Setup Wii Memory..."); INFO_LOG(BOOT, "Setup Wii Memory...");
// Write the 256 byte setting.txt to memory. This may not be needed as // Write the 256 byte setting.txt to memory.
// 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.
std::string settings_Filename(Common::GetTitleDataPath(TITLEID_SYSMENU) + WII_SETTING); std::string settings_Filename(Common::GetTitleDataPath(TITLEID_SYSMENU) + WII_SETTING);
std::string area, model, code, video, game; std::string area, model, code, video, game;
@ -217,13 +213,13 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
code = "L" + area.substr(0,1); code = "L" + area.substr(0,1);
game = area.substr(0,2); game = area.substr(0,2);
SettingsHandler gen; SettingsHandler gen;
std::string serno = ""; std::string serno = "";
if (File::Exists(settings_Filename)) if (File::Exists(settings_Filename))
{ {
File::IOFile settingsFileHandle(settings_Filename, "rb"); 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(); gen.Decrypt();
serno = gen.GetValue("SERNO"); serno = gen.GetValue("SERNO");
gen.Reset(); gen.Reset();
@ -231,10 +227,13 @@ bool CBoot::SetupWiiMemory(unsigned int _CountryCode)
File::Delete(settings_Filename); File::Delete(settings_Filename);
} }
if(serno.empty() || serno == "000000000"){ if (serno.empty() || serno == "000000000")
{
serno = gen.generateSerialNumber(); serno = gen.generateSerialNumber();
INFO_LOG(BOOT, "No previous serial number found, generated one instead: %s", serno.c_str()); 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()); 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"); 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"); PanicAlertT("SetupWiiMem: Cant create setting file");
return false; 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 // TODO Writes stuff to /shared2/nwc24/misc.bin
u32 update_misc = 0; u32 update_misc = 0;
static bool init = false;
switch (Parameter) switch (Parameter)
{ {
case IOCTL_NW24_GET_UNIVERSAL_TIME: case IOCTL_NW24_GET_UNIVERSAL_TIME: