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.
This commit is contained in:
Ryan Schmidt 2022-09-22 06:33:02 -05:00
parent 425bb8b054
commit 72322d65d7

View File

@ -81,6 +81,7 @@ class MiniVMacLauncher : public Launcher
void CopySystemFile(const std::string& fn, bool required); void CopySystemFile(const std::string& fn, bool required);
void ReadSystemResources(const std::string& systemFileName); void ReadSystemResources(const std::string& systemFileName);
uint16_t GetSystemVersion(); uint16_t GetSystemVersion();
std::string FindFolder(const std::string& folderType);
void MakeAlias(const std::string& dest, const std::string& src); void MakeAlias(const std::string& dest, const std::string& src);
fs::path ConvertImage(const fs::path& path); fs::path ConvertImage(const fs::path& path);
public: public:
@ -278,10 +279,11 @@ MiniVMacLauncher::MiniVMacLauncher(po::variables_map &options)
{ {
CopySystemFile("Finder", true); CopySystemFile("Finder", true);
CopySystemFile("System 7.5 Update", false); 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"); hfs_mkdir(vol, extensionsFolderName.c_str());
if(hfs_chdir(vol, "Extensions") != -1) if(hfs_chdir(vol, extensionsFolderName.c_str()) != -1)
{ {
CopySystemFile("Appearance Extension", false); CopySystemFile("Appearance Extension", false);
CopySystemFile("System 7 Tuner", false); CopySystemFile("System 7 Tuner", false);
@ -320,8 +322,9 @@ MiniVMacLauncher::MiniVMacLauncher(po::variables_map &options)
{ {
CopySystemFile("AutQuit7", true); CopySystemFile("AutQuit7", true);
MakeAlias("AutQuit7 alias", "AutQuit7"); MakeAlias("AutQuit7 alias", "AutQuit7");
hfs_mkdir(vol, "Startup Items"); std::string startupItemsFolderName = FindFolder("strt");
hfs_rename(vol, "AutQuit7 alias", "Startup Items"); hfs_mkdir(vol, startupItemsFolderName.c_str());
hfs_rename(vol, "AutQuit7 alias", startupItemsFolderName.c_str());
} }
else 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) bool MiniVMacLauncher::Go(int timeout)
{ {
fs::current_path(tempDir); fs::current_path(tempDir);