Logging / Config replated changes.
sa2 / applen add flag to load qt init file (--qt-ini) (read only for now) unify logging (--log) Signed-off-by: mariofutire@gmail.com <pi@raspberrypi>
This commit is contained in:
parent
bc74b5fbfb
commit
dab1735a69
8 changed files with 78 additions and 23 deletions
|
@ -1,15 +1,40 @@
|
|||
#include "frontends/common2/configuration.h"
|
||||
#include <frontends/common2/programoptions.h>
|
||||
|
||||
#include "Log.h"
|
||||
#include "linux/windows/files.h"
|
||||
#include "frontends/qapple/applicationname.h"
|
||||
|
||||
#include <boost/property_tree/ini_parser.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct KeyEncodedLess
|
||||
{
|
||||
static std::string decodeKey(const std::string & key)
|
||||
{
|
||||
std::string result = key;
|
||||
// quick implementation, just to make it work.
|
||||
// is there a library function available somewhere?
|
||||
boost::algorithm::replace_all(result, "%20", " ");
|
||||
return result;
|
||||
}
|
||||
|
||||
bool operator()( const std::string & lhs, const std::string & rhs ) const
|
||||
{
|
||||
const std::string key1 = decodeKey(lhs);
|
||||
const std::string key2 = decodeKey(rhs);
|
||||
return key1 < key2;
|
||||
}
|
||||
};
|
||||
|
||||
class Configuration
|
||||
{
|
||||
public:
|
||||
typedef boost::property_tree::basic_ptree<std::string, std::string, KeyEncodedLess> ini_t;
|
||||
|
||||
Configuration(const std::string & filename, const bool saveOnExit);
|
||||
~Configuration();
|
||||
|
||||
|
@ -21,13 +46,15 @@ namespace
|
|||
template<typename T>
|
||||
void putValue(const std::string & section, const std::string & key, const T & value);
|
||||
|
||||
const boost::property_tree::ptree & getProperties() const;
|
||||
const ini_t & getProperties() const;
|
||||
|
||||
private:
|
||||
const std::string myFilename;
|
||||
bool mySaveOnExit;
|
||||
const bool mySaveOnExit;
|
||||
|
||||
boost::property_tree::ptree myINI;
|
||||
static std::string decodeKey(const std::string & key);
|
||||
|
||||
ini_t myINI;
|
||||
};
|
||||
|
||||
std::shared_ptr<Configuration> Configuration::instance;
|
||||
|
@ -52,7 +79,7 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
const boost::property_tree::ptree & Configuration::getProperties() const
|
||||
const Configuration::ini_t & Configuration::getProperties() const
|
||||
{
|
||||
return myINI;
|
||||
}
|
||||
|
@ -74,8 +101,27 @@ namespace
|
|||
|
||||
}
|
||||
|
||||
void InitializeRegistry(const std::string & filename, const bool saveOnExit)
|
||||
void InitializeRegistry(const EmulatorOptions & options)
|
||||
{
|
||||
std::string filename;
|
||||
bool saveOnExit;
|
||||
|
||||
if (options.useQtIni)
|
||||
{
|
||||
const char* homeDir = getenv("HOME");
|
||||
if (!homeDir)
|
||||
{
|
||||
throw std::runtime_error("${HOME} not set, cannot locate Qt ini");
|
||||
}
|
||||
filename = std::string(homeDir) + "/.config/" + ORGANIZATION_NAME + "/" + APPLICATION_NAME + ".conf";
|
||||
saveOnExit = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
filename = "applen.conf";
|
||||
saveOnExit = options.saveConfigurationOnExit;
|
||||
}
|
||||
|
||||
Configuration::instance.reset(new Configuration(filename, saveOnExit));
|
||||
}
|
||||
|
||||
|
@ -144,8 +190,3 @@ void RegSaveValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD value)
|
|||
Configuration::instance->putValue(section, key, value);
|
||||
LogFileOutput("RegSaveValue: %s - %s = %d\n", section, key, value);
|
||||
}
|
||||
|
||||
const boost::property_tree::ptree & getProperties()
|
||||
{
|
||||
return Configuration::instance->getProperties();
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include "linux/windows/wincompat.h"
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <string>
|
||||
|
||||
void InitializeRegistry(const std::string & filename, const bool saveOnExit);
|
||||
struct EmulatorOptions;
|
||||
|
||||
const boost::property_tree::ptree & getProperties();
|
||||
void InitializeRegistry(const EmulatorOptions & options);
|
||||
|
||||
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser, LPTSTR buffer, DWORD chars);
|
||||
BOOL RegLoadValue (LPCTSTR section, LPCTSTR key, BOOL peruser, DWORD *value);
|
||||
|
|
|
@ -12,7 +12,8 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & vers
|
|||
po::options_description desc("AppleWin " + version);
|
||||
desc.add_options()
|
||||
("help,h", "Print this help message")
|
||||
("conf", "Save configuration on exit");
|
||||
("conf", "Save configuration on exit")
|
||||
("qt-ini", "Use Qt ini file (read only)");
|
||||
|
||||
po::options_description diskDesc("Disk");
|
||||
diskDesc.add_options()
|
||||
|
@ -51,6 +52,7 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & vers
|
|||
}
|
||||
|
||||
options.saveConfigurationOnExit = vm.count("conf");
|
||||
options.useQtIni = vm.count("qt-ini");
|
||||
|
||||
if (vm.count("d1"))
|
||||
{
|
||||
|
|
|
@ -6,13 +6,19 @@ struct EmulatorOptions
|
|||
std::string disk1;
|
||||
std::string disk2;
|
||||
bool createMissingDisks;
|
||||
|
||||
std::string snapshot;
|
||||
|
||||
int memclear;
|
||||
|
||||
bool log;
|
||||
|
||||
bool benchmark;
|
||||
bool headless;
|
||||
bool ntsc;
|
||||
|
||||
bool saveConfigurationOnExit;
|
||||
bool useQtIni; // use Qt .ini file (read only)
|
||||
|
||||
bool run; // false if options include "-h"
|
||||
};
|
||||
|
|
|
@ -137,7 +137,7 @@ namespace
|
|||
LogInit();
|
||||
}
|
||||
|
||||
InitializeRegistry("applen.conf", options.saveConfigurationOnExit);
|
||||
InitializeRegistry(options);
|
||||
|
||||
g_nMemoryClearType = options.memclear;
|
||||
|
||||
|
|
2
source/frontends/qapple/applicationname.h
Normal file
2
source/frontends/qapple/applicationname.h
Normal file
|
@ -0,0 +1,2 @@
|
|||
#define ORGANIZATION_NAME "AndSoft"
|
||||
#define APPLICATION_NAME "QAppleEmulator"
|
|
@ -6,14 +6,15 @@
|
|||
#include <QCommandLineParser>
|
||||
|
||||
#include "linux/version.h"
|
||||
#include "frontends/qapple/applicationname.h"
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication app(argc, argv);
|
||||
|
||||
QApplication::setOrganizationName("AndSoft");
|
||||
QApplication::setApplicationName("QAppleEmulator");
|
||||
QApplication::setOrganizationName(ORGANIZATION_NAME);
|
||||
QApplication::setApplicationName(APPLICATION_NAME);
|
||||
const QString qversion = QString::fromStdString(getVersion());
|
||||
QApplication::setApplicationVersion(qversion);
|
||||
|
||||
|
|
|
@ -32,9 +32,6 @@ namespace
|
|||
{
|
||||
void initialiseEmulator()
|
||||
{
|
||||
g_fh = fopen("/tmp/applewin.txt", "w");
|
||||
setbuf(g_fh, nullptr);
|
||||
|
||||
LogFileOutput("Initialisation\n");
|
||||
|
||||
ImageInitialize();
|
||||
|
@ -104,8 +101,7 @@ namespace
|
|||
|
||||
g_CardMgr.GetDisk2CardMgr().Destroy();
|
||||
ImageDestroy();
|
||||
fclose(g_fh);
|
||||
g_fh = nullptr;
|
||||
LogDone();
|
||||
}
|
||||
|
||||
SDL_Rect refreshTexture(const std::shared_ptr<SDL_Texture> & tex)
|
||||
|
@ -228,7 +224,15 @@ void run_sdl(int argc, const char * argv [])
|
|||
if (!run)
|
||||
return;
|
||||
|
||||
InitializeRegistry("applen.conf", options.saveConfigurationOnExit);
|
||||
|
||||
if (options.log)
|
||||
{
|
||||
LogInit();
|
||||
}
|
||||
|
||||
InitializeRegistry(options);
|
||||
|
||||
g_nMemoryClearType = options.memclear;
|
||||
|
||||
initialiseEmulator();
|
||||
loadEmulator();
|
||||
|
|
Loading…
Add table
Reference in a new issue