Exemple #1
0
        /**
         * Ensures that the "cfg" and "custom" folders exist under the "tf" directory. If not, they
         * will be silently created. If an attempted creation fails, the user will be alerted with
         * a dialog box.
         *
         * path: The path to the "tf" folder.
         *
         * Returns false if an attempt to create the appropriate subdirectories fails.
         * Throws an Exception if an unexpected error occurs.
         */
        private static bool VerifyTFSubdirectories(String path)
        {
            String cfg    = Path.Combine(path, "cfg");
            String custom = Path.Combine(path, "custom");

            // Despite being idempotent, only attempt the creation of the subdirectories if they are
            // confirmed to be missing. This is to reduce the chances of running into an exception.
            if (!Directory.Exists(cfg) || !Directory.Exists(custom))
            {
                try {
                    Directory.CreateDirectory(cfg);
                    Directory.CreateDirectory(custom);
                }
                catch (Exception) {
                    var dialog = new WarningDialog();
                    dialog.Display("The TF2 install path is missing the 'cfg' or 'custom' folder."
                                   + " The installer attempted to create this for you, but was"
                                   + " unable. Please open your 'Team Fortress 2\\tf' directory and"
                                   + " create these two folders, then re-run the installer.");
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
        /**
         * This event is triggered when the user clicks "Select Folder" to provide the path to their
         * TF2 installation.
         */
        private void ButtonPath_Click(object sender, EventArgs e)
        {
            String filepath = RequestTF2Filepath();

            if (filepath != null && filepath.Equals("cancel"))
            {
                // If the operation was cancelled, leave immediately without changing the state of
                // the program.
                return;
            }

            bool success = false;

            try {
                success = utilities.SetTFPath(filepath);
            }
            catch (Exception ex) {
                var dialog = new WarningDialog();
                dialog.Display("A problem occurred while trying to check that the file was valid."
                               + "The error message was: "
                               + Environment.NewLine
                               + Environment.NewLine
                               + ex.ToString());
            }
            if (success)
            {
                folderManuallySelected = true;

                nextPath.Enabled            = true;
                buttonPathMessage.ForeColor = Color.DimGray;
                buttonPathMessage.Text      = utilities.tfPath;
                promptPath.Text             = "The TF2 install path was recognized. Proceed to the next page.";
            }
            else
            {
                nextPath.Enabled            = false;
                buttonPathMessage.ForeColor = Color.Red;
                buttonPathMessage.Text      = "Invalid file provided. Please select your \"hl2\" file.";
                promptPath.Text             = INSTALL_NOT_FOUND;
            }
            buttonPathMessage.Visible = true;
        }
Exemple #3
0
        /**
         * Installs the neodefaults.cfg file. If there is an existing install, it will be
         * overwritten. This is executed on a background thread to avoid locking  the UI.
         */
        public async Task <InstallStatus> InstallConfig()
        {
            return(await Task.Run(() => {
                // First create the tf/cfg/NeoDefaults folder.
                String configFolderPath = "";
                try {
                    configFolderPath = Path.Combine(tfPath, "cfg", configFolderName);
                    Directory.CreateDirectory(configFolderPath);
                }
                catch (Exception e) {
                    log.WriteErr("An error occurred when trying to create the base folder for the config.",
                                 e.ToString());
                    return InstallStatus.FAIL;
                }


                // Create the config file.
                String sourceCfg = "";
                String destCfg = "";
                try {
                    sourceCfg = Path.Combine(componentsPath, sourceCfgName);
                    destCfg = Path.Combine(configFolderPath, destCfgName);

                    // If the config file already exists, remove the read-only attribute to allow
                    // overwriting the file.
                    if (File.Exists(destCfg))
                    {
                        File.SetAttributes(destCfg, FileAttributes.Normal);
                    }
                    CopyFile(sourceCfg, destCfg, true);
                }
                catch (Exception e) {
                    var logMsg = "An error occurred when trying to create '" + destCfg + "' from '"
                                 + sourceCfg + "'.";
                    log.WriteErr(logMsg, e.ToString());
                    return InstallStatus.FAIL;
                }


                // Create the custom file, if it does not already exist.
                try {
                    String sourceCustom = Path.Combine(componentsPath, customCfgName);
                    String destCustom = Path.Combine(configFolderPath, customCfgName);

                    // If there's already a custom file on the machine, then the user already
                    // has settings defined, so they should not be overridden.
                    if (!File.Exists(destCustom))
                    {
                        CopyFile(sourceCustom, destCustom, false);
                    }
                }
                catch (Exception e) {
                    log.WriteErr("Failed to create the " + customCfgName + " file.", e.ToString());
                    return InstallStatus.FAIL;
                }


                // Modify autoexec.cfg so that the newly installed config will execute when TF2
                // is launched.
                try {
                    AppendLinesToAutoExec(destCfg);
                }
                catch (Exception e) {
                    log.WriteErr("An error occurred when trying to append to autoexec.cfg.",
                                 e.ToString());

                    // Notify the user that they should modify this manually
                    String message = "Tried to modify 'autoexec.cfg' and failed. To fix this, try"
                                     + " re-running the installation. If the problem persists,"
                                     + " check the FAQ for how steps on how to do this manually.";
                    var dialog = new WarningDialog();
                    dialog.Display(message);
                    return InstallStatus.FAIL;
                }

                log.Write("Config installation complete.");
                return InstallStatus.SUCCESS;
            }));
        }