At the moment, all this can do is retrieve setup.ini from a selected
mirror and parse it.
---
 Makefile.am    |  22 +++++-
 cli/cyclops.cc | 186 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 207 insertions(+), 1 deletion(-)
 create mode 100644 cli/cyclops.cc

diff --git a/Makefile.am b/Makefile.am
index 6ae5dd6..5813e1a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -35,7 +35,10 @@ AM_CPPFLAGS = -D__USE_MINGW_ANSI_STDIO=1 
-D_FILE_OFFSET_BITS=64 -DLZMA_API_STATI
 inilex_CXXFLAGS:=-Wno-sign-compare
 iniparse_CXXFLAGS:=-Wno-free-nonheap-object
 
-noinst_PROGRAMS = @SETUP@$(EXEEXT) inilint
+noinst_PROGRAMS = \
+       @SETUP@$(EXEEXT) \
+       inilint \
+       cyclops
 
 noinst_LTLIBRARIES = \
        libsetupcore.la
@@ -214,6 +217,23 @@ IOSTREAM_PROVIDERS = \
        io_stream_file.cc \
        io_stream_file.h
 
+cyclops_SOURCES = \
+       $(IOSTREAM_PROVIDERS) \
+       cli/CliParseFeedback.cc \
+       cli/CliGetNetAuth.cc \
+       cli/CliGetUrlFeedback.cc \
+       cli/CliHashCheckFeedback.cc \
+       cli/CliFeedback.h \
+       cli/cyclops.cc \
+       res.rc
+
+cyclops_LDADD = \
+       libsetupcore.la \
+       libgetopt++/libgetopt++.la \
+       $(WININET)
+
+cyclops_LDFLAGS = -mconsole -Wc,-static -static-libtool-libs
+
 @SETUP@_LDADD = \
        libsetupcore.la \
        libgetopt++/libgetopt++.la \
diff --git a/cli/cyclops.cc b/cli/cyclops.cc
new file mode 100644
index 0000000..549b65a
--- /dev/null
+++ b/cli/cyclops.cc
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2020 Jon Turney
+ *
+ *     This program is free software; you can redistribute it and/or modify
+ *     it under the terms of the GNU General Public License as published by
+ *     the Free Software Foundation; either version 2 of the License, or
+ *     (at your option) any later version.
+ *
+ *     A copy of the GNU General Public License can be found at
+ *     http://www.gnu.org/
+ *
+ */
+
+/*
+ * The one-eyed hippo sees all!
+ */
+
+#include "CliGetNetAuth.h"
+#include "CliFeedback.h"
+#include "ini.h"
+#include "LogFile.h"
+#include "resource.h"
+#include "setup_version.h"
+#include "state.h"
+
+#include "ConnectionSetting.h"
+#include "KeysSetting.h"
+#include "SiteSetting.h"
+#include "UserSettings.h"
+#include "netio.h"
+
+#include "getopt++/GetOption.h"
+#include "getopt++/BoolOption.h"
+
+BoolOption UnsupportedOption (false, '\0', "allow-unsupported-windows", 
IDS_HELPTEXT_ALLOW_UNSUPPORTED_WINDOWS);
+static BoolOption HelpOption (false, 'h', "help", IDS_HELPTEXT_HELP);
+
+static void
+main_cli ()
+{
+  // installation RootDir is already established by read_mounts()
+  ConnectionSetting ConnectionSettings;
+  ExtraKeysSetting ExtraKeys;
+  SiteSetting ChosenSites;
+
+  // check windows version and abort if too low unless UnsupportedOption
+
+  // announce myself
+  std::cout << "cyclops " << setup_version << std::endl;
+
+  // mode of operation
+  // XXX: probably only support download and install mode
+  source = IDC_SOURCE_NETINST;
+
+  // XXX: local package cache dir (from options or setup.rc)
+  // (fetched setp.ini is stored here)
+  char cwd[MAX_PATH];
+  GetCurrentDirectory (MAX_PATH, cwd);
+  local_dir = std::string (cwd);
+
+  // proxy
+
+  // interactive network auth getter
+  NetIO::auth_getter = new CliGetNetAuth();
+
+  // mirror site
+
+  // fetch and parse ini file(s)
+  CliFeedback feedback;
+  bool succeeded = do_ini_thread(feedback);
+  Log (LOG_PLAIN) << "do_ini_thread: " << succeeded << endLog;
+}
+
+static void
+main_wrap ()
+{
+  UserSettings Settings;
+  Settings.load (std::string());
+  main_cli ();
+  Settings.save (); // Clean exit. save user options.
+}
+
+int
+main (int argc, char **argv)
+{
+  LogSingleton::SetInstance (*LogFile::createLogFile ());
+
+  bool help_option = false;
+  bool invalid_option = false;
+
+  if (!GetOption::GetInstance ().Process (argc, argv, NULL))
+      help_option = invalid_option = true;
+    else if (HelpOption)
+      help_option = true;
+
+  if (help_option)
+    {
+      if (invalid_option)
+        Log (LOG_PLAIN) << "\n" << LoadStringUtf8(IDS_HELPTEXT_ERROR) << "\n" 
<< endLog;
+
+      Log (LOG_PLAIN) << "\n" << LoadStringUtf8(IDS_HELPTEXT_HEADER) << "\n" 
<< endLog;
+      GetOption::GetInstance ().ParameterUsage (Log (LOG_PLAIN), 
LoadStringUtf8);
+
+      Logger ().exit (invalid_option ? 1 : 0, false);
+      return 1;
+    }
+
+  LogSingleton::SetInstance (*LogFile::createLogFile ());
+
+  main_wrap();
+
+  return 0;
+}
+
+/* --- */
+
+#include <windows.h>
+#include "String++.h"
+
+int
+mbox (HWND owner, const char *buf, const char *name, int type)
+{
+  Log (LOG_PLAIN) << "mbox " << name << ": " << buf << endLog;
+
+  // XXX: unattended_result?
+  return IDOK;
+}
+
+int
+mbox(HWND owner, unsigned int format_id, int mb_type, ...)
+{
+  std::wstring fmt = LoadStringWEx(format_id, MAKELANGID(LANG_ENGLISH, 
SUBLANG_ENGLISH_US));
+  if (fmt.empty())
+    fmt = L"Internal error: format string resource not found";
+
+  va_list args;
+  va_start(args, mb_type);
+  std::wstring buf = vformat(fmt, args);
+  va_end(args);
+
+  // write unlocalized to log as UTF8
+  Log (LOG_PLAIN) << "mbox " << ": " << wstring_to_string(buf) << endLog;
+
+  // XXX: unattended_result?
+  return IDOK;
+}
+
+static int
+mbox (HWND owner, const char *name, int type, int id, va_list args)
+{
+  char buf[1000], fmt[1000];
+
+  if (LoadString (GetModuleHandle(NULL), id, fmt, sizeof (fmt)) <= 0)
+    ExitProcess (0);
+
+  vsnprintf (buf, 1000, fmt, args);
+  return mbox(owner, buf, name, type);
+}
+
+void
+note (HWND owner, int id, ...)
+{
+  va_list args;
+  va_start (args, id);
+  mbox (owner, "note", MB_OK, id, args);
+}
+
+void
+fatal (HWND owner, int id, ...)
+{
+  va_list args;
+  va_start (args, id);
+  mbox (owner, "fatal", MB_OK, id, args);
+  Logger ().exit (1);
+}
+
+int
+yesno (HWND owner, int id, ...)
+{
+  va_list args;
+  va_start (args, id);
+  mbox (owner, "yesno", MB_YESNO, id, args);
+  Log (LOG_PLAIN) << "Y/N" << endLog;
+  // XXX: yesno response!!!
+  return IDYES;
+}
-- 
2.43.0

Reply via email to