diff --git a/LaunchAPPL/Client/MiniVMac.cc b/LaunchAPPL/Client/MiniVMac.cc index f58705c9d7..4312cd7ef2 100644 --- a/LaunchAPPL/Client/MiniVMac.cc +++ b/LaunchAPPL/Client/MiniVMac.cc @@ -142,9 +142,12 @@ 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(); + 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: @@ -266,7 +269,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"; @@ -343,10 +347,11 @@ MiniVMacLauncher::MiniVMacLauncher(po::variables_map &options) string finderFileName(bootblock1.begin() + 0x1B, bootblock1.begin() + 0x1B + bootblock1[0x1A]); CopySystemFile(finderFileName, 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); @@ -385,8 +390,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 { @@ -497,7 +503,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); @@ -507,12 +513,32 @@ 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]; } +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);