Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                Environment.SetEnvironmentVariable("CBLOADER", Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

                FileManager fm = new FileManager();
                StartupFlags sf = new StartupFlags();
                sf.LoadFromConfig(fm); // Don't require the config file. (Especially before checking we're in the right directory)
                if (!sf.ParseCmdArgs(args, fm))
                    return;
                Log.Info(String.Format("CBLoader version {0}", Version));
                CheckWorkingDirectory();
                fm.AddCustomFolder("custom");

                if (sf.CheckForUpdates && sf.UpdateFirst)
                    fm.DoUpdates(sf.ForcedReload);
                if (!sf.Mergelater)
                    fm.ExtractAndMerge(sf.ForcedReload);
                if (sf.LoadExec)
                {
                    if (sf.PatchFile)
                        ProcessManager.StartProcessAndPatchFile();
                    else
                        ProcessManager.StartProcessAndPatchMemory();
                }
                if (sf.Mergelater)
                    fm.ExtractAndMerge(sf.ForcedReload);

                Utils.CheckIfUserAssoc();
                // And here's the better alternated to DCUpdater.
                if (sf.CheckForUpdates && fm.DoUpdates(sf.ForcedReload))
                {
                    Log.Info("Character Builder has already been launched.\n  The following merges are not a bug, and not slowing down the loading of CB.");
                    fm.ExtractAndMerge(sf.ForcedReload);
                }

                if (sf.CheckForUpdates) // App Updates
                 {
                    Utils.CheckForNewVersion(Version);

                 }

            }
            catch (Exception e)
            {

                Log.Error(String.Empty, e);
            }
            if (Log.ErrorLogged)
            {
                Log.Info("Errors Encountered While Loading. Would you like to open the log file? (y/n)");
                if (Console.ReadKey().Key == ConsoleKey.Y)
                {
                    Process p = new Process();
                    p.StartInfo = new ProcessStartInfo("notepad.exe", Log.LogFile);
                    p.Start();
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Parses the command line arguments and sets the necessary state flags across the applicaiton.
 /// Returns a structure of startup flags to the caller.
 /// </summary>
 /// <returns>A structure containging flags important to how the application should load</returns>
 public bool ParseCmdArgs(string[] args, FileManager fm)
 {
     if (args != null && args.Length > 0)
     {
         for (int i = 0; i < args.Length; i++)
         {
             switch (args[i])
             {
                 case "-e": this.ForcedReload = true; break;
                 case "-n": this.LoadExec = false; break;
                 case "-v": Log.VerboseMode = true; break;
                 case "-p": this.PatchFile = true; break;
                 case "-a": Utils.UpdateRegistry(); break;
                 case "-u": 
                     FileManager.BasePath = getArgString(args, ref i);
                     if (!Directory.Exists(FileManager.BasePath))
                         Directory.CreateDirectory(FileManager.BasePath);
                     break;
                 case "-r":
                     FileManager.KeyFile = getArgString(args, ref i);
                     Utils.ExtractKeyFile(FileManager.KeyFile);
                     break;
                 case "-k":
                     FileManager.KeyFile = getArgString(args, ref i);
                     break;
                 case "-f":
                     fm.AddCustomFolder(getArgString(args, ref i));
                     break;
                 case "-c": // Load a different config file.
                     LoadFromConfig(fm,getArgString(args, ref i));
                     break;
                 case "-?":
                 case "-h":
                     Program.DisplayHelp();
                     return false;
                 // Fast Mode
                 case "+fm":
                     this.Mergelater = File.Exists(FileManager.MergedPath); break;
                 case "-fm":
                     this.Mergelater = false; break;
                 case "+d":
                     this.UpdateFirst = true;
                     this.LoadExec = false;
                     break;
                 case "-d":
                     CheckForUpdates = false;
                     break;
                 default:
                     if (File.Exists(args[i])) // Otherwise we lose the quotes, and Character builder can't find the file. (if there's whitespace in the path)
                         ProcessManager.EXECUTABLE_ARGS += " \"" + args[i] + "\"";
                     else
                         ProcessManager.EXECUTABLE_ARGS += " " + args[i];   // character Builder has args as well.  Lets pass unknown ones along.
                     break;
             }
         }
     }
     return true;
 }
Beispiel #3
0
 public bool LoadFromConfig(FileManager fm)
 {
     return LoadFromConfig(fm, CONFIG_FILENAME);
 }
Beispiel #4
0
        // The whole point of not using app.config was that we could have more than one.
        public bool LoadFromConfig(FileManager fm, string ConfigFile)
        {
            string fileName;
            fileName = ConfigFile;
            if (!File.Exists(fileName))
                fileName = Path.Combine(FileManager.BasePath, ConfigFile);
            if (!File.Exists(fileName))
                fileName = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),ConfigFile);
            if (!File.Exists(fileName))
                return false;

            Log.Debug("Loading Config File: " + fileName);
            try
            {
                SettingsType settings;
                using (StreamReader sr = new StreamReader(fileName))
                {
                    settings = (SettingsType)configSerializer.Deserialize(sr);
                }
                if (settings.Folders != null)
                    foreach (string customFolder in settings.Folders)
                        fm.AddCustomFolder(customFolder);
                if (settings.Ignore != null)
                    foreach (string ignoredPart in settings.Ignore)
                        fm.IgnoredParts.Add(ignoredPart.ToLower().Trim());
                if (settings.AlwaysRemergeSpecified)
                    this.ForcedReload = settings.AlwaysRemerge;
                if (!String.IsNullOrEmpty(settings.BasePath))
                {
                    FileManager.BasePath = Environment.ExpandEnvironmentVariables(settings.BasePath);
                    if (!Directory.Exists(FileManager.BasePath))
                        Directory.CreateDirectory(FileManager.BasePath);
                }
                if (!String.IsNullOrEmpty(settings.CBPath))
                    Environment.CurrentDirectory = Environment.ExpandEnvironmentVariables(settings.CBPath);
                if (settings.FastModeSpecified)
                    this.Mergelater = settings.FastMode;
                if (!String.IsNullOrEmpty(settings.KeyFile))
                    FileManager.KeyFile = Environment.ExpandEnvironmentVariables(settings.KeyFile);
                if (settings.VerboseModeSpecified)
                    Log.VerboseMode = settings.VerboseMode;
                if (settings.UpdateFirstSpecified)
                    this.UpdateFirst = settings.UpdateFirst;
                if (settings.LaunchBuilderSpecified)
                    this.LoadExec = settings.LaunchBuilder;
                if (settings.NewMergeLogicSpecified)
                    fm.UseNewMergeLogic = settings.NewMergeLogic;
                if (settings.ShowChangelogSpecified)
                    UpdateLog.ShowChangelog = settings.ShowChangelog;
            }
            catch (Exception e)
            {
                Log.Error("Error Loading Config File", e);
                return false;
            }
            return true;
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            try
            {
                Environment.SetEnvironmentVariable("CBLOADER", Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));

                FileManager fm = new FileManager();
                StartupFlags sf = new StartupFlags();
                sf.LoadFromConfig(fm); // Don't require the config file. (Especially before checking we're in the right directory)
                if (!sf.ParseCmdArgs(args, fm))
                    return;
                Log.Info(String.Format("CBLoader version {0}", Version));
                CheckWorkingDirectory();
                fm.AddCustomFolder("custom");

                if (sf.CheckForUpdates && sf.UpdateFirst)
                    fm.DoUpdates(sf.ForcedReload);
                if (!sf.Mergelater)
                    fm.ExtractAndMerge(sf.ForcedReload);
                if (sf.LoadExec)
                {
                    if (sf.PatchFile)
                        ProcessManager.StartProcessAndPatchFile();
                    else
                        ProcessManager.StartProcessAndPatchMemory();
                }
                if (sf.Mergelater)
                    fm.ExtractAndMerge(sf.ForcedReload);

                Utils.CheckIfUserAssoc();
                // And here's the better alternated to DCUpdater.
                if (sf.CheckForUpdates && fm.DoUpdates(sf.ForcedReload))
                {
                    Log.Info("Character Builder has already been launched.\n  The following merges are not a bug, and not slowing down the loading of CB.");
                    fm.ExtractAndMerge(sf.ForcedReload);
                }

                /*
                // From Jeff: this is kinda creepy to have. We'll leave it for now though.
                //   Stephen:   My only issue is the fact that it pops up as an additional cmd window for a quarter of a second. I'll find a better way of doing it.
                //     I've now made a better way of doing it. (See FileManager.CheckMetaData).  This should now be Obsolete, and therefore removable.
                // Checks for updates.  http://www.donationcoder.com/Software/Mouser/Updater/help/index.html for details.
                if (File.Exists("dcuhelper.exe"))
                {
                    // Eventually I want to keep CBLoader up to date with it; for now, leave it there for the sole 
                    // purpose of sharing my homebrew with my players.  The useful thing about DCUpdater is that it can handle multiple update files with no extra effort, just put them into the folder.
                    ProcessStartInfo dcuhelper = new ProcessStartInfo("dcuhelper.exe", "-ri \"CBLoader\" \".\" \".\" -shownew -check -nothingexit");
                    dcuhelper.WindowStyle = ProcessWindowStyle.Minimized;
                    Process.Start(dcuhelper);
                }
                */
            }
            catch (Exception e)
            {
                
                Log.Error(String.Empty, e);
            }
            if (Log.ErrorLogged)
            {
                Log.Info("Errors Encountered While Loading. Would you like to open the log file? (y/n)");
                if (Console.ReadKey().Key == ConsoleKey.Y)
                {
                    Process p = new Process();
                    p.StartInfo = new ProcessStartInfo("notepad.exe", Log.LogFile);
                    p.Start();
                }
            }
        }