Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="switchableFile"></param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentException">NormalFile, CustomFile, TempFile, or RelativeRoot contain
        /// invalid characters.</exception>
        /// <exception cref="System.ArgumentNullException">NormalFile, CustomFile, TempFile, or RelativeRoot
        /// are null.</exception>
        public static FileSwitcher AsFileSwitcher(this ISwitchableFile switchableFile)
        {
            FileSwitcher fileSwitcher = new FileSwitcher();

            fileSwitcher.NormalFile = switchableFile.ResolveNormalFile();
            fileSwitcher.CustomFile = switchableFile.ResolveCustomFile();
            fileSwitcher.TempFile   = switchableFile.ResolveTempFile();
            fileSwitcher.FileType   = switchableFile.FileType;
            return(fileSwitcher);
        }
Beispiel #2
0
        /// <summary>
        /// Fixes switchable files that are in an inconsistent state. If they are not in an inconsistent state,
        /// does nothing.
        /// </summary>
        /// <param name="switchableFile"></param>
        /// <param name="wereBroken">Set to true if the files were in an inconsistent state.</param>
        /// <exception cref="System.IO.IOException">There was an error while fixing the files.</exception>
        /// <exception cref="System.ArgumentException">NormalFile, CustomFile, or TempFile contain invalid
        /// characters.</exception>
        /// <exception cref="System.ArgumentNullException">NormalFile, CustomFile, or TempFile are null.</exception>
        public static void FixBrokenFilesIfNeeded(this ISwitchableFile switchableFile, out bool wereBroken)
        {
            FileSwitcher files = switchableFile.AsFileSwitcher();

            files.FixBrokenFiles(out wereBroken);
        }
Beispiel #3
0
        public int Run()
        {
            if (m_parsedArgs.ShowVersion)
            {
                Console.WriteLine("{0} version {1}", VersionInfo.AssemblyTitle, VersionInfo.AssemblyVersion);
                Console.WriteLine(VersionInfo.AssemblyCopyright);
                Console.WriteLine(VersionInfo.LicenseStatement);
            }
            if (m_parsedArgs.ShowHelp)
            {
                CommandLineArgs.DisplayHelp(Console.Out);
            }

            if (m_parsedArgs.ShowVersion || m_parsedArgs.ShowHelp)
            {
                return(0);
            }

            bool invalidArgs = false;

            if (m_parsedArgs.Settings.Username == null)
            {
                Logging.Log.FatalFormat("You must supply a username.");
                invalidArgs = true;
            }

            if (m_parsedArgs.Settings.Password == null)
            {
                Logging.Log.FatalFormat("You must supply a password.");
                invalidArgs = true;
            }

            if (invalidArgs)
            {
                Console.WriteLine("Try {0} --help for usage information.", CommandLineArgs.GetProgramName());
                return(1);
            }

            if (m_parsedArgs.Settings.ClosePopup != null)
            {
                m_launcher.Params.ClosePopup = m_parsedArgs.Settings.ClosePopup.Value;
            }
            if (m_parsedArgs.Settings.DfoDir != null)
            {
                m_launcher.Params.GameDir = m_parsedArgs.Settings.DfoDir;
            }
            if (m_parsedArgs.Settings.LaunchWindowed != null)
            {
                m_launcher.Params.LaunchInWindowed = m_parsedArgs.Settings.LaunchWindowed.Value;
            }
            if (m_parsedArgs.Settings.GameWindowWidth != null)
            {
                m_launcher.Params.WindowWidth = m_parsedArgs.Settings.GameWindowWidth;
            }
            if (m_parsedArgs.Settings.GameWindowHeight != null)
            {
                m_launcher.Params.WindowHeight = m_parsedArgs.Settings.GameWindowHeight;
            }
            if (m_parsedArgs.Settings.Password != null)
            {
                m_launcher.Params.Password = m_parsedArgs.Settings.Password;
            }
            if (m_parsedArgs.Settings.Username != null)
            {
                m_launcher.Params.Username = m_parsedArgs.Settings.Username;
            }

            if (m_parsedArgs.Settings.DfoDir == null)
            {
                try
                {
                    m_launcher.Params.AutoDetectGameDir();
                }
                catch (IOException ex)
                {
                    Logging.Log.ErrorFormat("Could not autodetect the DFO directory. {0}", ex.Message);
                }
            }

            foreach (SwitchableFile switchableFile in m_parsedArgs.Settings.SwitchableFiles.Values)
            {
                switchableFile.RelativeRoot = m_launcher.Params.GameDir;
                switchableFile.ApplyDefaults();

                if (m_parsedArgs.Settings.SwitchFile[switchableFile.Name].HasValue &&
                    m_parsedArgs.Settings.SwitchFile[switchableFile.Name].Value)
                {
                    FileSwitcher fileToSwitch = switchableFile.AsFileSwitcher();
                    m_launcher.Params.FilesToSwitch.Add(fileToSwitch);
                }
            }

            try
            {
                FixSwitchableFilesIfNeeded(m_parsedArgs.Settings.SwitchableFiles.Values);
            }
            catch (IOException ex)
            {
                Logging.Log.FatalFormat(
                    "Error while trying to fix switchable file. {0} I guess you'll have to fix it yourself.",
                    ex.Message);

                return(2);
            }

            m_launcher.LaunchStateChanged += StateChangedHandler;
            m_launcher.FileSwitchFailed   += FileSwitchFailHandler;
            m_launcher.WindowModeFailed   += WindowFailHandler;
            m_launcher.PopupKillFailed    += PopupKillFailHandler;

            Console.WriteLine("You must leave this program running. It will automatically stop when the game is closed.");

            try
            {
                Logging.Log.InfoFormat("Launching.");
                m_launcher.Launch();

                Logging.Log.DebugFormat("Waiting for state to become None.");
                m_stateBecameNoneEvent.WaitOne();

                Logging.Log.DebugFormat("Done.");
                Console.WriteLine("Done.");
            }
            catch (Exception ex)
            {
                if (ex is System.Security.SecurityException ||
                    ex is System.Net.WebException ||
                    ex is DfoAuthenticationException ||
                    ex is DfoLaunchException)
                {
                    Logging.Log.FatalFormat("There was a problem while trying to start the game. {0}", ex.Message);
                    return(2);
                }
                else
                {
                    throw;
                }
            }

            return(0);
        }