From: Jon Turney <jon.turney@dronecode.org.uk>
To: cygwin-apps@cygwin.com
Cc: Jon Turney <jon.turney@dronecode.org.uk>
Subject: [PATCH setup 10/16] Move setup.ini pathame components to ini.cc
Date: Fri, 8 Mar 2024 18:34:29 +0000 [thread overview]
Message-ID: <20240308183440.4263-11-jon.turney@dronecode.org.uk> (raw)
In-Reply-To: <20240308183440.4263-1-jon.turney@dronecode.org.uk>
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
next prev parent reply other threads:[~2024-03-08 18:36 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-08 18:34 [PATCH setup 00/16] Groundwork for a GUI-less installation tool Jon Turney
2024-03-08 18:34 ` [PATCH setup 01/16] Drop forward declaration of non-existent class IniState Jon Turney
2024-03-08 18:34 ` [PATCH setup 02/16] Move setup_exts[] to the only place it's used Jon Turney
2024-03-08 18:34 ` [PATCH setup 03/16] Split GuiParseFeedback out from ini fetcher Jon Turney
2024-03-08 18:34 ` [PATCH setup 04/16] Split out site into SiteSettings and SitePage Jon Turney
2024-03-08 18:34 ` [PATCH setup 05/16] Don't call Antivirus::AtExit() directly from Logger::exit() Jon Turney
2024-03-08 18:34 ` [PATCH setup 06/16] Simplify invocation of UserSettings::open_settings() Jon Turney
2024-03-08 18:34 ` [PATCH setup 07/16] Split out URL fetching progress reporting Jon Turney
2024-03-08 18:34 ` [PATCH setup 08/16] Instantiate found_ini_list in ini.cc Jon Turney
2024-03-08 18:34 ` [PATCH setup 09/16] Move is_64bit to state Jon Turney
2024-03-08 18:34 ` Jon Turney [this message]
2024-03-08 18:34 ` [PATCH setup 11/16] Drop hinstance global Jon Turney
2024-03-08 18:34 ` [PATCH setup 12/16] Spit out GetNetAuth from NetIO Jon Turney
2024-03-08 18:34 ` [PATCH setup 13/16] Split out hash checking progress reporting Jon Turney
2024-03-08 18:34 ` [PATCH setup 14/16] Push check_for_cached into package_source Jon Turney
2024-03-08 18:34 ` [PATCH setup 15/16] Put various shared subcomponents into a convenience library Jon Turney
2024-03-08 18:34 ` [PATCH setup 16/16] Add beginnings of a command line installation tool Jon Turney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240308183440.4263-11-jon.turney@dronecode.org.uk \
--to=jon.turney@dronecode.org.uk \
--cc=cygwin-apps@cygwin.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).