From 425bb8b0542ac5c53d492512d119874ad4cd691d Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Thu, 22 Sep 2022 05:27:51 -0500 Subject: [PATCH 1/2] MiniVMac.cc: New method ReadSystemResources Move the System file resource-reading code out of GetSystemVersion and into a new ReadSystemResources method which stores the resources in a new member variable so that it can be used by multiple methods. --- LaunchAPPL/Client/MiniVMac.cc | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/LaunchAPPL/Client/MiniVMac.cc b/LaunchAPPL/Client/MiniVMac.cc index 199e658fb0..5e6046278f 100644 --- a/LaunchAPPL/Client/MiniVMac.cc +++ b/LaunchAPPL/Client/MiniVMac.cc @@ -76,9 +76,11 @@ class MiniVMacLauncher : public Launcher hfsvol *sysvol; hfsvol *vol; + std::unique_ptr systemRes; void CopySystemFile(const std::string& fn, bool required); - uint16_t GetSystemVersion(const std::string& systemFileName); + void ReadSystemResources(const std::string& systemFileName); + uint16_t GetSystemVersion(); void MakeAlias(const std::string& dest, const std::string& src); fs::path ConvertImage(const fs::path& path); public: @@ -200,7 +202,8 @@ MiniVMacLauncher::MiniVMacLauncher(po::variables_map &options) hfs_setcwd(sysvol, ent.blessed); string systemFileName(bootblock1.begin() + 0xB, bootblock1.begin() + 0xB + bootblock1[0xA]); - uint16_t sysver = GetSystemVersion(systemFileName); + ReadSystemResources(systemFileName); + uint16_t sysver = GetSystemVersion(); bool usesAutQuit7 = (sysver >= 0x700); std::string optionsKey = usesAutQuit7 ? "autquit7-image" : "autoquit-image"; @@ -424,7 +427,7 @@ void MiniVMacLauncher::MakeAlias(const std::string& dest, const std::string& src } -uint16_t MiniVMacLauncher::GetSystemVersion(const std::string& systemFileName) +void MiniVMacLauncher::ReadSystemResources(const std::string& systemFileName) { hfsdirent fileent; hfs_stat(sysvol, systemFileName.c_str(), &fileent); @@ -434,8 +437,13 @@ uint16_t MiniVMacLauncher::GetSystemVersion(const std::string& systemFileName) hfs_read(system, buffer.data(), fileent.u.file.rsize); hfs_close(system); std::istringstream systemResStream(std::string((char*)buffer.data(), buffer.size())); - Resources systemRes(systemResStream); - Resource vers = systemRes.resources[ResRef('vers', 1)]; + systemRes = std::make_unique(systemResStream); +} + + +uint16_t MiniVMacLauncher::GetSystemVersion() +{ + Resource vers = systemRes->resources[ResRef('vers', 1)]; return (uint16_t)vers.getData()[0] << 8 | vers.getData()[1]; } From 72322d65d74f9ca9191fa242f933342e8458c04a Mon Sep 17 00:00:00 2001 From: Ryan Schmidt Date: Thu, 22 Sep 2022 06:33:02 -0500 Subject: [PATCH 2/2] MiniVMac.cc: New method FindFolder Remove hardcoded Extensions and Startup Items folder names and get the correct localized names from the System file's 'fld#' resource. --- LaunchAPPL/Client/MiniVMac.cc | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/LaunchAPPL/Client/MiniVMac.cc b/LaunchAPPL/Client/MiniVMac.cc index 5e6046278f..ae58f1e2c6 100644 --- a/LaunchAPPL/Client/MiniVMac.cc +++ b/LaunchAPPL/Client/MiniVMac.cc @@ -81,6 +81,7 @@ class MiniVMacLauncher : public Launcher void CopySystemFile(const std::string& fn, bool required); void ReadSystemResources(const std::string& systemFileName); uint16_t GetSystemVersion(); + std::string FindFolder(const std::string& folderType); void MakeAlias(const std::string& dest, const std::string& src); fs::path ConvertImage(const fs::path& path); public: @@ -278,10 +279,11 @@ MiniVMacLauncher::MiniVMacLauncher(po::variables_map &options) { CopySystemFile("Finder", true); CopySystemFile("System 7.5 Update", false); - if(hfs_chdir(sysvol, "Extensions") != -1) + std::string extensionsFolderName = FindFolder("extn"); + if(hfs_chdir(sysvol, extensionsFolderName.c_str()) != -1) { - hfs_mkdir(vol, "Extensions"); - if(hfs_chdir(vol, "Extensions") != -1) + hfs_mkdir(vol, extensionsFolderName.c_str()); + if(hfs_chdir(vol, extensionsFolderName.c_str()) != -1) { CopySystemFile("Appearance Extension", false); CopySystemFile("System 7 Tuner", false); @@ -320,8 +322,9 @@ MiniVMacLauncher::MiniVMacLauncher(po::variables_map &options) { CopySystemFile("AutQuit7", true); MakeAlias("AutQuit7 alias", "AutQuit7"); - hfs_mkdir(vol, "Startup Items"); - hfs_rename(vol, "AutQuit7 alias", "Startup Items"); + std::string startupItemsFolderName = FindFolder("strt"); + hfs_mkdir(vol, startupItemsFolderName.c_str()); + hfs_rename(vol, "AutQuit7 alias", startupItemsFolderName.c_str()); } else { @@ -448,6 +451,21 @@ uint16_t MiniVMacLauncher::GetSystemVersion() } +std::string MiniVMacLauncher::FindFolder(const std::string& folderType) +{ + Resource fld = systemRes->resources[ResRef('fld#', 0)]; + size_t i = 0; + while (i < fld.getData().size()) + { + unsigned char len = fld.getData()[i + 7]; + if (fld.getData().substr(i, 4) == folderType) + return fld.getData().substr(i + 8, len); + i += 8 + len + len % 2; + } + return "unknown"; +} + + bool MiniVMacLauncher::Go(int timeout) { fs::current_path(tempDir);