Move SetupBaseNameOption to ini.cc Eliminate SetupIniDir, it's just SetupArch + "/" Change SetupArch() and SetupBaseName() into functions --- fromcwd.cc | 8 ++++---- ini.cc | 22 +++++++++++++++++----- ini.h | 5 ++--- main.cc | 8 -------- 4 files changed, 23 insertions(+), 20 deletions(-)
diff --git a/fromcwd.cc b/fromcwd.cc index 3e77ad3..7acc0ec 100644 --- a/fromcwd.cc +++ b/fromcwd.cc @@ -53,7 +53,7 @@ public: ext != setup_ext_list.end (); ext++, fi++) { - if (!casecompare (SetupBaseName + "." + *ext, theFile->cFileName)) + if (!casecompare (SetupBaseName() + "." + *ext, theFile->cFileName)) *fi = true; } } @@ -63,7 +63,7 @@ public: { if (level <= 0) return; - inidir = !casecompare (SetupArch, aDir->cFileName); + inidir = !casecompare (SetupArch(), aDir->cFileName); if (level == 1 && !inidir) return; Find aFinder (basePath + aDir->cFileName); @@ -75,8 +75,8 @@ public: { if (*fi) { - found_ini_list.push_back (basePath + SetupArch + "/" - + SetupBaseName + "." + *ext); + found_ini_list.push_back (basePath + SetupArch() + "/" + + SetupBaseName() + "." + *ext); /* * Terminate the search after the first setup file * found, which shadows any setup files with diff --git a/ini.cc b/ini.cc index 3ef1311..6eefcac 100644 --- a/ini.cc +++ b/ini.cc @@ -47,6 +47,7 @@ #include "threebar.h" #include "getopt++/BoolOption.h" +#include "getopt++/StringOption.h" #include "IniDBBuilderPackage.h" #include "compress.h" #include "Exception.h" @@ -61,6 +62,7 @@ std::string ini_setup_version; IniList setup_ext_list (setup_exts, setup_exts + (sizeof(setup_exts) / sizeof(*setup_exts))); +static StringOption SetupBaseNameOption ("setup", 'i', "ini-basename", IDS_HELPTEXT_INI_BASENAME, false); static BoolOption NoVerifyOption (false, 'X', "no-verify", IDS_HELPTEXT_NO_VERIFY); static BoolOption NoVersionCheckOption (false, '\0', "no-version-check", IDS_HELPTEXT_NO_VERSION_CHECK); @@ -146,6 +148,16 @@ private: int yyerror_count; }; +std::string SetupArch() +{ + return is_64bit ? "x86_64" : "x86"; +} + +std::string SetupBaseName() +{ + return SetupBaseNameOption; +} + static io_stream* decompress_ini (io_stream *ini_file, std::string ¤t_ini_name) { @@ -255,7 +267,7 @@ do_local_ini (HWND owner) if (!ini_file || sig_fail) { // no setup found or signature invalid - note (owner, IDS_SETUPINI_MISSING, SetupBaseName.c_str (), + note (owner, IDS_SETUPINI_MISSING, SetupBaseName().c_str (), "localdir"); ini_error = true; } @@ -265,7 +277,7 @@ do_local_ini (HWND owner) myFeedback.babble ("Found ini file - " + current_ini_name); myFeedback.iniName (current_ini_name); int ldl = local_dir.length () + 1; - int cap = current_ini_name.rfind ("/" + SetupArch); + int cap = current_ini_name.rfind ("/" + SetupArch()); aBuilder.parse_mirror = rfc1738_unescape (current_ini_name.substr (ldl, cap - ldl)); ini_init (ini_file, &aBuilder, myFeedback); @@ -311,7 +323,7 @@ do_remote_ini (HWND owner) ext++) { current_ini_ext = *ext; - current_ini_name = n->url + SetupIniDir + SetupBaseName + "." + current_ini_ext; + current_ini_name = n->url + SetupArch() + "/" + SetupBaseName() + "." + current_ini_ext; current_ini_sig_name = current_ini_name + ".sig"; ini_sig_file = get_url_to_membuf (current_ini_sig_name, owner); ini_file = get_url_to_membuf (current_ini_name, owner); @@ -326,7 +338,7 @@ do_remote_ini (HWND owner) if (!ini_file || sig_fail) { // no setup found or signature invalid - note (owner, IDS_SETUPINI_MISSING, SetupBaseName.c_str (), n->url.c_str ()); + note (owner, IDS_SETUPINI_MISSING, SetupBaseName().c_str (), n->url.c_str ()); ini_error = true; } else @@ -346,7 +358,7 @@ do_remote_ini (HWND owner) /* save known-good setup.ini locally */ const std::string fp = "file://" + local_dir + "/" + rfc1738_escape_part (n->url) + - "/" + SetupIniDir + SetupBaseName + ".ini"; + "/" + SetupArch() + "/" + SetupBaseName() + ".ini"; io_stream::mkpath_p (PATH_TO_FILE, fp, 0); if (io_stream *out = io_stream::open (fp, "wb", 0)) { diff --git a/ini.h b/ini.h index 68072b0..e318a8a 100644 --- a/ini.h +++ b/ini.h @@ -24,9 +24,8 @@ typedef std::vector <std::string> IniList; extern IniList found_ini_list, setup_ext_list; const std::string setup_exts[] = { "zst", "xz", "bz2", "ini" }; extern bool is_new_install; -extern std::string SetupArch; -extern std::string SetupIniDir; -extern std::string SetupBaseName; +std::string SetupArch(); +std::string SetupBaseName(); class IniState; class IniDBBuilder; diff --git a/main.cc b/main.cc index ea74887..6ae3256 100644 --- a/main.cc +++ b/main.cc @@ -83,7 +83,6 @@ extern char **_argv; #endif bool is_new_install = false; -std::string SetupArch; std::string SetupIniDir; HINSTANCE hinstance; @@ -108,14 +107,11 @@ static BoolOption NoAdminOption (false, 'B', "no-admin", IDS_HELPTEXT_NO_ADMIN); static BoolOption WaitOption (false, 'W', "wait", IDS_HELPTEXT_WAIT); static BoolOption HelpOption (false, 'h', "help", IDS_HELPTEXT_HELP); static BoolOption VersionOption (false, 'V', "version", IDS_HELPTEXT_VERSION); -static StringOption SetupBaseNameOpt ("setup", 'i', "ini-basename", IDS_HELPTEXT_INI_BASENAME, false); BoolOption UnsupportedOption (false, '\0', "allow-unsupported-windows", IDS_HELPTEXT_ALLOW_UNSUPPORTED_WINDOWS); static BoolOption DeprecatedOption (false, 'w', "no-warn-deprecated-windows", IDS_HELPTEXT_NO_WARN_DEPRECATED_WINDOWS); static StringChoiceOption SymlinkTypeOption(symlink_types, '\0', "symlink-type", IDS_HELPTEXT_SYMLINK_TYPE, false, SymlinkTypeMagic); static StringOption GuiLangOption ("", '\0', "lang", IDS_HELPTEXT_LANG); -std::string SetupBaseName; - static void inline set_cout () { @@ -297,10 +293,6 @@ WinMain (HINSTANCE h, bool output_only = help_option || VersionOption; - SetupBaseName = SetupBaseNameOpt; - SetupArch = is_64bit ? "x86_64" : "x86"; - SetupIniDir = SetupArch+"/"; - /* Initialize well known SIDs. We need the admin SID to test if we're supposed to elevate. */ nt_sec.initialiseWellKnownSIDs (); -- 2.45.1