mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-09 22:18:58 +01:00
move SettingsHandler to Common lib
This commit is contained in:
parent
c8129bc802
commit
ac0883044e
@ -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
|
||||
|
@ -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" />
|
||||
|
@ -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" />
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -1,50 +1,51 @@
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// 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
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
// Thanks to Treeki for writing the original class - 29/01/2012
|
||||
|
||||
#ifndef _SETTINGS_HANDLER_H
|
||||
#define _SETTINGS_HANDLER_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common.h"
|
||||
#include "../CoreParameter.h"
|
||||
#define SETTINGS_SIZE 0x100
|
||||
|
||||
class SettingsHandler
|
||||
{
|
||||
public:
|
||||
SettingsHandler();
|
||||
|
||||
void AddSetting(const char *key, const char *value);
|
||||
|
||||
const u8 *GetData() const;
|
||||
const std::string GetValue(std::string key);
|
||||
|
||||
void Decrypt();
|
||||
void Reset();
|
||||
std::string generateSerialNumber();
|
||||
private:
|
||||
void WriteByte(u8 b);
|
||||
|
||||
u8 m_buffer[SETTINGS_SIZE];
|
||||
u32 m_position, m_key;
|
||||
std::string decoded;
|
||||
};
|
||||
|
||||
#endif
|
||||
// Copyright (C) 2003 Dolphin Project.
|
||||
|
||||
// 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
|
||||
// the Free Software Foundation, version 2.0.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official SVN repository and contact information can be found at
|
||||
// http://code.google.com/p/dolphin-emu/
|
||||
|
||||
// Thanks to Treeki for writing the original class - 29/01/2012
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "Common.h"
|
||||
|
||||
class SettingsHandler
|
||||
{
|
||||
public:
|
||||
SettingsHandler();
|
||||
|
||||
enum
|
||||
{
|
||||
SETTINGS_SIZE = 0x100
|
||||
};
|
||||
|
||||
void AddSetting(const char *key, const char *value);
|
||||
|
||||
const u8 *GetData() const;
|
||||
const std::string GetValue(const std::string key);
|
||||
|
||||
void Decrypt();
|
||||
void Reset();
|
||||
const std::string generateSerialNumber();
|
||||
|
||||
private:
|
||||
void WriteByte(u8 b);
|
||||
|
||||
u8 m_buffer[SETTINGS_SIZE];
|
||||
u32 m_position, m_key;
|
||||
std::string decoded;
|
||||
};
|
@ -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" />
|
||||
|
@ -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" />
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user