Move SetupBaseNameOption to ini.cc
Eliminate SetupIniDir, it's just SetupArch + "/"
Change SetupArch() and SetupBaseName() into functions, to avoid having
to do global initialization at the right time.
---
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 c53eede..b1f1021 100644
--- a/fromcwd.cc
+++ b/fromcwd.cc
@@ -52,7 +52,7 @@ public:
ext != setup_ext_list.end ();
ext++, fi++)
{
- if (!casecompare (SetupBaseName + "." + *ext, theFile->cFileName))
+ if (!casecompare (SetupBaseName() + "." + *ext,
theFile->cFileName))
*fi = true;
}
}
@@ -62,7 +62,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);
@@ -74,8 +74,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 2b2da10..42df6a3 100644
--- a/ini.cc
+++ b/ini.cc
@@ -44,6 +44,7 @@
#include "io_stream_memory.h"
#include "getopt++/BoolOption.h"
+#include "getopt++/StringOption.h"
#include "IniDBBuilderPackage.h"
#include "compress.h"
#include "msg.h"
@@ -58,10 +59,21 @@ IniList setup_ext_list (setup_exts,
setup_exts + (sizeof(setup_exts) /
sizeof(*setup_exts)));
IniList found_ini_list;
+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);
+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)
{
@@ -170,7 +182,7 @@ do_local_ini (Feedback &myFeedback)
if (!ini_file || sig_fail)
{
// no setup found or signature invalid
- note (myFeedback.owner(), IDS_SETUPINI_MISSING, SetupBaseName.c_str
(),
+ note (myFeedback.owner(), IDS_SETUPINI_MISSING, SetupBaseName().c_str
(),
"localdir");
ini_error = true;
}
@@ -180,7 +192,7 @@ do_local_ini (Feedback &myFeedback)
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);
@@ -225,7 +237,7 @@ do_remote_ini (Feedback &myFeedback)
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, myFeedback);
ini_file = get_url_to_membuf (current_ini_name, myFeedback);
@@ -240,7 +252,7 @@ do_remote_ini (Feedback &myFeedback)
if (!ini_file || sig_fail)
{
// no setup found or signature invalid
- note (myFeedback.owner(), IDS_SETUPINI_MISSING, SetupBaseName.c_str
(), n->url.c_str ());
+ note (myFeedback.owner(), IDS_SETUPINI_MISSING, SetupBaseName().c_str
(), n->url.c_str ());
ini_error = true;
}
else
@@ -260,7 +272,7 @@ do_remote_ini (Feedback &myFeedback)
/* 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 2ca4f5b..05b31e0 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;
extern bool is_new_install;
-extern std::string SetupArch;
-extern std::string SetupIniDir;
-extern std::string SetupBaseName;
+std::string SetupArch();
+std::string SetupBaseName();
class io_stream;
class IniDBBuilder;
diff --git a/main.cc b/main.cc
index c359ba9..4c391f5 100644
--- a/main.cc
+++ b/main.cc
@@ -84,7 +84,6 @@ extern char **_argv;
#endif
bool is_new_install = false;
-std::string SetupArch;
std::string SetupIniDir;
HINSTANCE hinstance;
@@ -109,14 +108,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 ()
{
@@ -298,10 +294,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.43.0