From 3224d6598837cb7ded4175bcb29f9ce8c23be73c Mon Sep 17 00:00:00 2001 From: Vinyl Darkscratch Date: Wed, 14 Dec 2016 21:09:33 -0800 Subject: [PATCH] Made paths in script cross-platform friendly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An ending that made me very, VERY teary-eyed, interrupted by an access denied error…argh, code bugs, why! >~< Basically, the path to “My Games” and the name of the journal’s executable are now defined by oneshot.cpp and loaded into the Ruby script, so the ending isn’t interrupted. Now all that’s left is to compile the journal! --- binding-mri/oneshot-binding.cpp | 2 ++ scripts/SaveLoad.rb | 7 +++---- scripts/Script.rb | 16 +++++++++------- src/oneshot.cpp | 20 ++++++++++++++++++++ src/oneshot.h | 2 ++ 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/binding-mri/oneshot-binding.cpp b/binding-mri/oneshot-binding.cpp index 447730d..84761ce 100644 --- a/binding-mri/oneshot-binding.cpp +++ b/binding-mri/oneshot-binding.cpp @@ -75,6 +75,8 @@ void oneshotBindingInit() rb_const_set(module, rb_intern("USER_NAME"), rb_str_new2(shState->oneshot().userName().c_str())); rb_const_set(module, rb_intern("SAVE_PATH"), rb_str_new2(shState->oneshot().savePath().c_str())); rb_const_set(module, rb_intern("DOCS_PATH"), rb_str_new2(shState->oneshot().docsPath().c_str())); + rb_const_set(module, rb_intern("GAME_PATH"), rb_str_new2(shState->oneshot().gamePath().c_str())); + rb_const_set(module, rb_intern("JOURNAL"), rb_str_new2(shState->oneshot().journal().c_str())); rb_const_set(module, rb_intern("LANG"), rb_str_new2(shState->oneshot().lang().c_str())); rb_const_set(msg, rb_intern("INFO"), INT2FIX(Oneshot::MSG_INFO)); rb_const_set(msg, rb_intern("YESNO"), INT2FIX(Oneshot::MSG_YESNO)); diff --git a/scripts/SaveLoad.rb b/scripts/SaveLoad.rb index a761c3f..35c382e 100644 --- a/scripts/SaveLoad.rb +++ b/scripts/SaveLoad.rb @@ -1,15 +1,14 @@ SAVE_FILE_NAME = Oneshot::SAVE_PATH + '/save.dat' PERMA_FLAGS_NAME = Oneshot::SAVE_PATH + '/p-settings.dat' -FAKE_SAVE_NAME = Oneshot::DOCS_PATH + '\\My Games\\Oneshot\\save_progress.oneshot' - +FAKE_SAVE_NAME = Oneshot::GAME_PATH + '/Oneshot/save_progress.oneshot' def erase_game File.delete(SAVE_FILE_NAME) end def fake_save - Dir.mkdir(Oneshot::DOCS_PATH + "\\My Games") unless File.exists?(Oneshot::DOCS_PATH + "\\My Games") - Dir.mkdir(Oneshot::DOCS_PATH + "\\My Games\\Oneshot") unless File.exists?(Oneshot::DOCS_PATH + "\\My Games\\Oneshot") + Dir.mkdir(Oneshot::GAME_PATH) unless File.exists?(Oneshot::GAME_PATH) + Dir.mkdir(Oneshot::GAME_PATH + "/Oneshot") unless File.exists?(Oneshot::GAME_PATH + "/Oneshot") File.open(FAKE_SAVE_NAME, 'wb') do |file| # Wrire frame count for measuring play time Marshal.dump(Graphics.frame_count, file) diff --git a/scripts/Script.rb b/scripts/Script.rb index cbd3e8c..e8fc179 100644 --- a/scripts/Script.rb +++ b/scripts/Script.rb @@ -277,18 +277,20 @@ module Script end def self.copy_journal - Dir.mkdir(Oneshot::DOCS_PATH + "\\My Games") unless File.exists?(Oneshot::DOCS_PATH + "\\My Games") - Dir.mkdir(Oneshot::DOCS_PATH + "\\My Games\\Oneshot") unless File.exists?(Oneshot::DOCS_PATH + "\\My Games\\Oneshot") - File.open("_______.exe", "rb") do |input| - File.open(Oneshot::DOCS_PATH + "\\My Games\\Oneshot\\_______.exe","wb") do |output| - while buff = input.read(4096) - output.write(buff) + Dir.mkdir(Oneshot::GAME_PATH) unless File.exists?(Oneshot::GAME_PATH) + Dir.mkdir(Oneshot::GAME_PATH + "/Oneshot") unless File.exists?(Oneshot::GAME_PATH + "/Oneshot") + if File.exists?(Oneshot::JOURNAL) + File.open(Oneshot::JOURNAL, "rb") do |input| + File.open(Oneshot::GAME_PATH + "/Oneshot/" + Oneshot::JOURNAL,"wb") do |output| + while buff = input.read(4096) + output.write(buff) + end end end end if File.exists?("README.txt") File.open("README.txt", "rb") do |input| - File.open(Oneshot::DOCS_PATH + "\\My Games\\Oneshot\\README.txt","wb") do |output| + File.open(Oneshot::GAME_PATH + "/Oneshot/README.txt","wb") do |output| while buff = input.read(4096) output.write(buff) end diff --git a/src/oneshot.cpp b/src/oneshot.cpp index 6c3adfe..7e89289 100644 --- a/src/oneshot.cpp +++ b/src/oneshot.cpp @@ -219,6 +219,8 @@ struct OneshotPrivate std::string userName; std::string savePath; std::string docsPath; + std::string gamePath; + std::string journal; //Dialog text std::string txtYes; @@ -409,6 +411,8 @@ Oneshot::Oneshot(RGSSThreadData &threadData) : WCHAR path[MAX_PATH]; SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, path); p->docsPath = w32_fromWide(path); + p->gamePath = p->docsPath+"\\My Games"; + p->journal = "_______.exe"; #else //Get language code const char *lc_all = getenv("LC_ALL"); @@ -446,6 +450,12 @@ Oneshot::Oneshot(RGSSThreadData &threadData) : //Get documents path char *path = xdg_user_dir_lookup_with_fallback("DOCUMENTS", getenv("HOME")); p->docsPath = path; + p->gamePath = path; + #ifdef OS_OSX + p->journal = "_______.app"; + #elif defined OS_LINUX + p->journal = "_______"; + #endif free(path); #endif @@ -603,6 +613,16 @@ const std::string &Oneshot::docsPath() const return p->docsPath; } +const std::string &Oneshot::gamePath() const +{ + return p->gamePath; +} + +const std::string &Oneshot::journal() const +{ + return p->journal; +} + const std::vector &Oneshot::obscuredMap() const { return p->obscuredMap; diff --git a/src/oneshot.h b/src/oneshot.h index e0fe686..2f30912 100644 --- a/src/oneshot.h +++ b/src/oneshot.h @@ -49,6 +49,8 @@ public: const std::string &userName() const; const std::string &savePath() const; const std::string &docsPath() const; + const std::string &gamePath() const; + const std::string &journal() const; const std::vector &obscuredMap() const; bool obscuredCleared() const; bool allowExit() const;