refactor filename string handling
This commit is contained in:
parent
3c504822f0
commit
6ce62c6bc2
|
@ -93,19 +93,19 @@ E2wxApp::~E2wxApp() {
|
|||
|
||||
|
||||
static std::filesystem::path dirCache() {
|
||||
return std::filesystem::path(wxStandardPaths::Get().GetUserDir(wxStandardPaths::Dir_Cache).t_str());
|
||||
return std::filesystem::path(wxStandardPaths::Get().GetUserDir(wxStandardPaths::Dir_Cache).fn_str().data());
|
||||
}
|
||||
|
||||
static std::filesystem::path dirConfig() {
|
||||
return std::filesystem::path(wxStandardPaths::Get().GetUserConfigDir().t_str());
|
||||
return std::filesystem::path(wxStandardPaths::Get().GetUserConfigDir().fn_str().data());
|
||||
}
|
||||
|
||||
static std::filesystem::path dirDocuments() {
|
||||
return std::filesystem::path(wxStandardPaths::Get().GetAppDocumentsDir().t_str());
|
||||
return std::filesystem::path(wxStandardPaths::Get().GetAppDocumentsDir().fn_str().data());
|
||||
}
|
||||
|
||||
static std::filesystem::path dirResources() {
|
||||
return std::filesystem::path(wxStandardPaths::Get().GetResourcesDir().t_str());
|
||||
return std::filesystem::path(wxStandardPaths::Get().GetResourcesDir().fn_str().data());
|
||||
}
|
||||
|
||||
|
||||
|
@ -137,18 +137,18 @@ bool E2wxApp::OnInit() {
|
|||
|
||||
|
||||
|
||||
this->confdir = dirConfig() / std::filesystem::path((GetID()+wxT(".d")).t_str());
|
||||
this->confdir = dirConfig() / std::filesystem::path((GetID()+wxT(".d")).fn_str().data());
|
||||
std::filesystem::create_directories(this->confdir);
|
||||
BOOST_LOG_TRIVIAL(info) << "Configuration directory path: " << this->confdir;
|
||||
|
||||
this->conffile = dirConfig() / std::filesystem::path(GetID().t_str());
|
||||
this->conffile = dirConfig() / std::filesystem::path(GetID().fn_str().data());
|
||||
BOOST_LOG_TRIVIAL(info) << "Configuration file path: " << this->conffile;
|
||||
wxConfigBase::Set(new wxFileConfig("", "", GetID()));
|
||||
|
||||
this->docsdir = dirDocuments() / std::filesystem::path(GetID().t_str());
|
||||
this->docsdir = dirDocuments() / std::filesystem::path(GetID().fn_str().data());
|
||||
BOOST_LOG_TRIVIAL(info) << "User document directory path: " << this->docsdir;
|
||||
|
||||
const std::filesystem::path exe = std::filesystem::path(stdpaths.GetExecutablePath().t_str());
|
||||
const std::filesystem::path exe = std::filesystem::path(stdpaths.GetExecutablePath().fn_str().data());
|
||||
std::cout << "Executable file path: " << exe << std::endl;
|
||||
std::filesystem::path res = exe.parent_path();
|
||||
if (res.filename() == "bin" || res.filename() == "MacOS") {
|
||||
|
@ -161,7 +161,7 @@ bool E2wxApp::OnInit() {
|
|||
res /= "Resources";
|
||||
}
|
||||
this->resdir = res;
|
||||
std::cout << "Resource directory path: " << this->resdir << std::endl;
|
||||
std::cout << "Resource directory path: " << this->resdir.c_str() << std::endl;
|
||||
|
||||
wxXmlResource::Get()->InitAllHandlers();
|
||||
if (!wxXmlResource::Get()->LoadAllFiles(this->resdir.c_str())) {
|
||||
|
@ -177,7 +177,7 @@ bool E2wxApp::OnInit() {
|
|||
|
||||
|
||||
this->emu = new Emulator();
|
||||
Config cfg((const std::string)this->arg_configfile.c_str());
|
||||
Config cfg(this->arg_configfile);
|
||||
this->emu->config(cfg);
|
||||
this->emu->init();
|
||||
this->emu_timer = new EmuTimer(this->emu);
|
||||
|
@ -235,8 +235,8 @@ bool E2wxApp::OnCmdLineParsed(wxCmdLineParser& parser) {
|
|||
if (n <= 0) {
|
||||
std::cout << "no config file specified on the command line; will use config file specified in user-preferences" << std::endl;
|
||||
} else {
|
||||
this->arg_configfile = parser.GetParam(0);
|
||||
std::cout << "using config file specified on the command line: " << this->arg_configfile << std::endl;
|
||||
this->arg_configfile = std::filesystem::path(parser.GetParam(0).fn_str().data());
|
||||
std::cout << "using config file specified on the command line: " << this->arg_configfile.c_str() << std::endl;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -277,7 +277,7 @@ const std::filesystem::path E2wxApp::GetDocumentsDir() const {
|
|||
const std::filesystem::path E2wxApp::BuildLogFilePath() const {
|
||||
std::filesystem::path logfile =
|
||||
dirCache() /
|
||||
std::filesystem::path(GetID().t_str()) /
|
||||
std::filesystem::path(GetID().fn_str().data()) /
|
||||
std::filesystem::path(wxT("log"));
|
||||
|
||||
std::filesystem::create_directories(logfile);
|
||||
|
|
|
@ -58,7 +58,7 @@ class E2wxApp : public wxApp {
|
|||
std::filesystem::path conffile;
|
||||
std::filesystem::path confdir;
|
||||
std::filesystem::path docsdir;
|
||||
wxString arg_configfile;
|
||||
std::filesystem::path arg_configfile;
|
||||
EmuTimer *emu_timer;
|
||||
Emulator *emu;
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
wxDirTraverseResult OnFile(const wxString& filename) {
|
||||
wxFileName n = wxFileName::FileName(filename);
|
||||
if (n.GetExt() == "conf") {
|
||||
const std::filesystem::path& full = std::filesystem::path(n.GetFullName().t_str());
|
||||
const std::filesystem::path& full = std::filesystem::path(n.GetFullName().fn_str().data());
|
||||
const std::filesystem::path path = m_dir / full;
|
||||
m_tree->AppendItem(m_parent, n.GetName(), -1, -1, new TreeItemData(path, m_editable));
|
||||
}
|
||||
|
@ -220,7 +220,7 @@ const std::filesystem::path BuildNewConfFilePath() {
|
|||
|
||||
wxString ts = to_iso_string(boost::posix_time::microsec_clock::universal_time());
|
||||
ts.Replace(wxT("."), wxT("_"));
|
||||
f /= (wxT("Untitled_") + ts + wxT(".conf")).t_str();
|
||||
f /= (wxT("Untitled_") + ts + wxT(".conf")).fn_str().data();
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "will create file: " << f.c_str();
|
||||
|
||||
|
@ -302,7 +302,7 @@ void PreferencesDialog::OnRename(wxCommandEvent& evt) {
|
|||
if (fn.Exists()) {
|
||||
wxMessageBox(wxT("That name is already being used."), wxT("File exists"), wxOK|wxCENTER, this);
|
||||
} else {
|
||||
const std::filesystem::path newpath(fn.GetFullPath().t_str());
|
||||
const std::filesystem::path newpath(fn.GetFullPath().fn_str().data());
|
||||
std::filesystem::rename(data->path(), newpath);
|
||||
BuildItemTree();
|
||||
PreSelectUserConfigItemName(newpath);
|
||||
|
|
|
@ -63,12 +63,11 @@ static std::uint16_t memory_block_size(const std::string &block_size) {
|
|||
|
||||
unsigned char Config::disk_mask(0);
|
||||
|
||||
Config::Config(const std::string& file_path):
|
||||
file_path(file_path)
|
||||
Config::Config(const std::filesystem::path& f):
|
||||
file_path(f)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Config::~Config()
|
||||
{
|
||||
}
|
||||
|
@ -104,7 +103,7 @@ void Config::parse(MemoryRandomAccess& ram, Memory& rom, Slots& slts, int& revis
|
|||
{
|
||||
std::ifstream* pConfig;
|
||||
|
||||
std::string path(this->file_path);
|
||||
std::filesystem::path path(this->file_path);
|
||||
|
||||
if (!path.empty())
|
||||
{
|
||||
|
@ -128,18 +127,13 @@ void Config::parse(MemoryRandomAccess& ram, Memory& rom, Slots& slts, int& revis
|
|||
// TODO what to do when no config?
|
||||
user_config = wxT("epple2");
|
||||
}
|
||||
user_config += ".conf";
|
||||
|
||||
std::filesystem::path f = wxGetApp().GetConfigDir();
|
||||
f /= user_config.t_str();
|
||||
f += ".conf";
|
||||
path = f.string();
|
||||
path = wxGetApp().GetConfigDir() / user_config.fn_str().data();
|
||||
std::cout << "looking for config file: " << path << std::endl;
|
||||
pConfig = new std::ifstream(path.c_str());
|
||||
if (!pConfig->is_open()) {
|
||||
f = wxGetApp().GetResDir();
|
||||
f /= user_config.t_str();
|
||||
f += ".conf";
|
||||
path = f.string();
|
||||
path = wxGetApp().GetResDir() / user_config.fn_str().data();
|
||||
std::cout << "looking for config file: " << path << std::endl;
|
||||
pConfig = new std::ifstream(path.c_str());
|
||||
if (!pConfig->is_open()) {
|
||||
|
@ -237,6 +231,7 @@ void Config::parse(MemoryRandomAccess& ram, Memory& rom, Slots& slts, int& revis
|
|||
|
||||
// TODO: make sure there is no more than ONE stdin and/or ONE stdout card
|
||||
}
|
||||
|
||||
void Config::parseLine(const std::string& line, MemoryRandomAccess& ram, Memory& rom, Slots& slts, int& revision, ScreenImage& gui, CassetteIn& cassetteIn, CassetteOut& cassetteOut, Apple2* apple2)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#ifndef CONFIGEP2_H
|
||||
#define CONFIGEP2_H
|
||||
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
class Memory;
|
||||
class MemoryRandomAccess;
|
||||
|
@ -35,7 +36,7 @@ public:
|
|||
|
||||
class Config {
|
||||
private:
|
||||
const std::string& file_path;
|
||||
const std::filesystem::path file_path;
|
||||
static unsigned char disk_mask;
|
||||
|
||||
static void loadDisk(Slots& slts, int slot, int drive, const std::string& fnib);
|
||||
|
@ -45,7 +46,7 @@ private:
|
|||
static void tryParseLine(const std::string& line, MemoryRandomAccess& ram, Memory& rom, Slots& slts, int& revision, ScreenImage& gui, CassetteIn& cassetteIn, CassetteOut& cassetteOut, Apple2* apple2);
|
||||
|
||||
public:
|
||||
Config(const std::string& file_path);
|
||||
Config(const std::filesystem::path& f);
|
||||
~Config();
|
||||
|
||||
void parse(MemoryRandomAccess& ram, Memory& rom, Slots& slts, int& revision, ScreenImage& gui, CassetteIn& cassetteIn, CassetteOut& cassetteOut, Apple2* apple2);
|
||||
|
|
Loading…
Reference in New Issue