Ejemplo n.º 1
0
        public static void ValidateNetLogPath(string altPath)
        {
            // override to avoid net log logic
            if (!settingsRef.DisableNetLogs)
            {
                if (string.IsNullOrEmpty(settingsRef.NetLogPath) || !CheckIfFileOpens(Path.Combine(Directory.GetParent(settingsRef.NetLogPath).ToString(), "AppConfig.xml")))
                {
                    // let's just ask the user where to look
                    OpenFileDialog x = new OpenFileDialog()
                    {
                        Title  = "TD Helper - Select a valid Elite: Dangerous AppConfig.xml",
                        Filter = "AppConfig.xml|*.xml"
                    };

                    if (x.ShowDialog() == DialogResult.OK)
                    {
                        t_AppConfigPath        = x.FileName;
                        settingsRef.NetLogPath = Path.Combine(Directory.GetParent(t_AppConfigPath).ToString(), "Logs"); // set the appropriate Logs folder

                        SaveSettingsToIniFile();
                        ValidateVerboseLogging(); // always validate if verboselogging is enabled
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(altPath) && Directory.Exists(settingsRef.NetLogPath) && settingsRef.NetLogPath.EndsWith("Logs"))
                        {
                            t_AppConfigPath        = Path.Combine(Directory.GetParent(altPath).ToString(), "AppConfigLocal.xml");
                            settingsRef.NetLogPath = altPath;

                            SaveSettingsToIniFile();
                            ValidateVerboseLogging(); // always validate if verboselogging is enabled
                        }
                        else
                        {
                            DialogResult dialog2 = TopMostMessageBox.Show(
                                true,
                                true,
                                "Cannot set NetLogPath to a valid directory.\r\nWe will disable scanning for recent systems, if you want to re-enable it, set a working path.",
                                "TD Helper - Error",
                                MessageBoxButtons.OK);

                            settingsRef.DisableNetLogs = true;

                            SaveSettingsToIniFile();
                        }
                    }
                }
                else
                {
                    // derive our AppConfig.xml path from NetLogPath
                    t_AppConfigPath = Path.Combine(Directory.GetParent(settingsRef.NetLogPath).ToString(), "AppConfig.xml");

                    // double check the verbose logging state
                    ValidateVerboseLogging();
                }
            }
        }
Ejemplo n.º 2
0
        private void ResetButton_Click(object sender, EventArgs e)
        {
            DialogResult d = TopMostMessageBox.Show(
                false,
                true,
                "This will wipe all configuration settings currently loaded, are you sure?",
                "TD Helper - Warning",
                MessageBoxButtons.YesNo);

            if (d == DialogResult.Yes)
            {
                MainForm.callForReset = true;
                this.Dispose();
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Process the maintenance reqest.
        /// </summary>
        /// <param name="command">The command to be issued.</param>
        /// <param name="message">The message to be displayed.</param>
        private void ProcessMaintenanceRequest(
            string command,
            string message = "")
        {
            if (string.IsNullOrEmpty(message))
            {
                MainForm.DBUpdateCommandString = command;
                Close();
            }
            else
            {
                // Display warning message and ask for input.
                DialogResult dialog = TopMostMessageBox.Show(
                    true,
                    true,
                    message,
                    "TD Helper - Warning",
                    MessageBoxButtons.YesNoCancel);

                switch (dialog)
                {
                case DialogResult.Cancel:
                    // Do nothing and leave the form open.
                    break;

                case DialogResult.No:
                    // Reset the output parameters and close the form.
                    MainForm.DBUpdateCommandString = string.Empty;

                    Close();

                    break;

                case DialogResult.Yes:
                    // Set the output parameters and close the form.
                    MainForm.DBUpdateCommandString = command;

                    Close();

                    break;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Process the reqest for a database update.
        /// </summary>
        private void ProcessDdUpdateRequest()
        {
            // Check for the options needing warnings.
            if (chkClean.Checked)
            {
                // Display warning message and ask for input.
                DialogResult dialog = TopMostMessageBox.Show(
                    true,
                    true,
                    "The clean option will erase the entire database and rebuild from empty. Are you sure you want to do this?",
                    "TD Helper - Warning",
                    MessageBoxButtons.YesNoCancel);

                switch (dialog)
                {
                case DialogResult.Cancel:
                    // Do nothing and leave the form open.
                    break;

                case DialogResult.No:
                    // Reset the output parameters and close the form.
                    MainForm.DBUpdateCommandString = string.Empty;

                    Close();

                    break;

                case DialogResult.Yes:
                    // Set the output parameters and close the form.
                    MainForm.DBUpdateCommandString = GetDbUpdateCommandString();

                    Close();

                    break;
                }
            }
            else
            {
                MainForm.DBUpdateCommandString = GetDbUpdateCommandString();

                Close();
            }
        }
Ejemplo n.º 5
0
        public static bool DownloadFile(string url, string outputPath)
        {
            // generic file downloader with a timeout
            bool result = false;

            try
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

                using (Downloader client = new Downloader())
                {
                    client.DownloadFile(url, outputPath);
                }

                result = true;
            }
            catch (TimeoutException)
            {
                DialogResult d = TopMostMessageBox.Show(
                    true,
                    true,
                    "HTTP download request timed out, retry?",
                    "TD Helper - Error",
                    MessageBoxButtons.YesNo);

                if (d == DialogResult.Yes)
                {
                    result = DownloadFile(url, outputPath); // retry
                }
            }
            catch (Exception e)
            {
                if (e.Message != "The remote server returned an error: (404) Not Found.")
                {
                    WriteToLog(MainForm.updateLogPath, "[URL: {0}] {1}".With(
                                   url,
                                   e.GetFullMessage()));
                }
            }

            return(result);
        }
Ejemplo n.º 6
0
        public static void ValidateVerboseLogging()
        {
            // Open the AppConfig file and check to see if the setting is found.
            string path = t_AppConfigPath;

            XDocument file          = XDocument.Load(path, LoadOptions.PreserveWhitespace);
            XElement  parentElement = file.Element("AppConfig");
            XElement  element       = parentElement.Element("Network");
            bool      elementFound  = !(element.Attribute("VerboseLogging") == null);;

            if (!elementFound)
            {
                // Not found in AppConfig.xml so check to see if there is an AppConfigLocal.xml file and check that.
                path = Path.Combine(Path.GetDirectoryName(path), "AppConfigLocal.xml");

                if (File.Exists(path))
                {
                    file          = XDocument.Load(path, LoadOptions.PreserveWhitespace);
                    parentElement = file.Element("AppConfig");
                    element       = parentElement.Element("Network");
                    elementFound  = !(element.Attribute("VerboseLogging") == null);
                }
            }

            if (elementFound)
            {
                // The VerboseLogging element has been found in the file pointed to by path so check for the correct value.
                elementFound = int.Parse(element.Attribute("VerboseLogging").Value) == 1;
            }

            if (!elementFound)
            {
                // If elementFound is false at this point, then VerboseLogging was either not found or it was found but not set.
                // Ask the user if we can set it.
                DialogResult dialog = TopMostMessageBox.Show(
                    true,
                    true,
                    "VerboseLogging isn't set, it must be corrected so we can grab recent systems.\r\n\nMay we fix it?",
                    "TD Helper - Error",
                    MessageBoxButtons.YesNo);

                if (dialog == DialogResult.Yes)
                {
                    SetVerboseLogging(path); // so fix it
                }
                else
                {
                    DialogResult dialog2 = TopMostMessageBox.Show(
                        true,
                        true,
                        "We will set the DisableNetLogs override in our config file to prevent prompts.\r\n",
                        "TD Helper - Notice",
                        MessageBoxButtons.OK);

                    settingsRef.DisableNetLogs = true;
                }
            }

            if (!settingsRef.DisableNetLogs)
            {
                // refresh our path to the first netlog
                latestLogPaths = CollectLogPaths(settingsRef.NetLogPath, "netLog*.log");

                recentLogPath
                    = latestLogPaths != null && latestLogPaths.Count > 0
                    ? latestLogPaths[0]
                    : string.Empty;
            }
        }
Ejemplo n.º 7
0
        public static DialogResult ValidateNetLogPath(
            string altPath,
            bool force = false)
        {
            DialogResult result = DialogResult.None;

            // override to avoid net log logic
            if (!settingsRef.DisableNetLogs)
            {
                CheckDefaultNetLogPaths();

                string appConfigPath = string.Empty;

                if (!string.IsNullOrEmpty(settingsRef.NetLogPath))
                {
                    appConfigPath = Path.Combine(
                        Directory.GetParent(settingsRef.NetLogPath).ToString(),
                        "AppConfig.xml");
                }

                if (force ||
                    string.IsNullOrEmpty(settingsRef.NetLogPath) ||
                    string.IsNullOrEmpty(appConfigPath) ||
                    !CheckIfFileOpens(appConfigPath))
                {
                    // let's just ask the user where to look
                    OpenFileDialog x = new OpenFileDialog()
                    {
                        Title  = "TD Helper - Select a valid Elite: Dangerous AppConfig.xml",
                        Filter = "AppConfig.xml|*.xml"
                    };

                    result = x.ShowDialog();

                    if (result != DialogResult.Cancel)
                    {
                        // set the appropriate Logs folder
                        t_AppConfigPath        = x.FileName;
                        settingsRef.NetLogPath = Path.Combine(Directory.GetParent(t_AppConfigPath).ToString(), "Logs");

                        SaveSettingsToIniFile();

                        SetSplashScreenStatus("Validating verbose logging");

                        // always validate when verboselogging is enabled
                        verboseLoggingChecked = false;
                        ValidateVerboseLogging();
                    }
                    else
                    {
                        DialogResult dialog2 = TopMostMessageBox.Show(
                            true,
                            true,
                            "Scanning for recent systems has been disabled.",
                            "TD Helper - Error",
                            MessageBoxButtons.OK);

                        settingsRef.DisableNetLogs = true;

                        SaveSettingsToIniFile();
                    }
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
        private static void Main(string[] args)
        {
            try
            {
                using (Mutex mutex = new Mutex(false, "Global\\" + MainForm.AssemblyGuid))
                {
                    if (!mutex.WaitOne(0, false))
                    {
                        return;
                    }

                    if (args.Length == 1 && args[0] == "/noupdate")
                    {
                        updateOverride = true; // flag us as override
                    }
                    else if (args.Length == 1 && args[0] == "/g")
                    {
                        TopMostMessageBox.Show(
                            true,
                            true,
                            "You must include a URL pointing to a Zip file surrounded by quotes as your second argument!\r\nExample:  TDHelper.exe /g \"http://localhost:90/File.zip\"",
                            "TD Helper - Argument Error",
                            MessageBoxButtons.OK);

                        return;
                    }
                    else if (args.Length == 2 && args[0] == "/g")
                    {
                        if (UpdateClass.IsValidURLArchive(args[1]))
                        {
                            DialogResult d = TopMostMessageBox.Show(
                                true,
                                true,
                                "We will now generate a manifest file in the current directory.",
                                "TD Helper - Confirm",
                                MessageBoxButtons.OKCancel);

                            if (d == DialogResult.OK)
                            {
                                UpdateClass.GenerateManifest(
                                    MainForm.assemblyPath,
                                    Path.Combine(MainForm.assemblyPath, "TDHelper.manifest"),
                                    args[1]);
                                return;
                            }
                        }
                    }
                    else if (args.Length == 1 && args[0] == "/?")
                    {
                        TopMostMessageBox.Show(
                            true,
                            true,
                            "Proper commandline arguments are:\r\n\r\n\t/noupdate   Disables auto-update.\r\n\t/g [URL]       Specifies a URL to assign as the package in the manifest.\r\n\t/?\t   This help message box.",
                            "TD Helper - Argument Help",
                            MessageBoxButtons.OK);

                        return;
                    }

                    string version = AssemblyName
                                     .GetAssemblyName("TDHelper.exe")
                                     .Version
                                     .ToString();

                    SplashScreen.ShowSplashScreen();
                    SplashScreen.SetVersion(version);

                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }
            }
            catch (Exception ex)
            {
                // Get the path to the error log.
                string errorLogPath = Path.Combine(
                    Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location),
                    "error.log");

                // Get the exception message plus any inner exception messages.
                string    message = DateTime.Now.ToString("yyyy//MM/dd hh:mm:ss") + " : " + ex.Message;
                Exception pointer = ex.InnerException;

                while (pointer != null && string.IsNullOrEmpty(pointer.Message))
                {
                    message += Environment.NewLine + pointer.Message;
                }

                // Append the message to the error log
                File.AppendAllText(
                    errorLogPath,
                    message + Environment.NewLine + Environment.NewLine,
                    System.Text.Encoding.Default);

                // Show an error dialog to the user.
                MessageBox.Show(
                    "An error occured when running TDHelper. Please close this mesage box and try again. If this continues to happen please contact the administrator. Thanks.",
                    "TD Helper - Error",
                    MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 9
0
        public static void GenerateManifest(string workingPath, string manifest, string URL)
        {
            /*
             * Take a set of files, calculate data for each (assembly first),
             * print the list to a manifest in XML in the working directory.
             */

            XDocument doc  = new XDocument(new XElement("Manifest"));
            XElement  root = doc.Element("Manifest");

            try
            {
                // let's make a proper manifest xml from the list of files
                if (Directory.Exists(workingPath) && Directory.GetFiles(workingPath).Length > 0)
                {
                    // only the non-debugging assembly
                    string[] fileList =
                    {
                        "TDHelper.exe",
                        "System.Data.SQLite.dll",
                        "Newtonsoft.Json.dll",
                        "SharpConfig.dll"
                    };

                    // put the assembly info first
                    if (!string.IsNullOrEmpty(fileList[0]))
                    {
                        string assemblyVersion = GetFileVersion(fileList[0]);
                        string assemblyMD5     = CalculateMD5(fileList[0]);
                        string assemblyExeName = Path.GetFileName(fileList[0]);

                        root.Add(new XElement(
                                     "Assembly",
                                     new XAttribute("Name", assemblyExeName),
                                     new XElement("Version", assemblyVersion),
                                     new XElement("MD5", assemblyMD5)));

                        if (!string.IsNullOrEmpty(URL))
                        {
                            XElement el = root.Element("Assembly");
                            el.Add(new XElement("URL", URL));
                        }
                        else
                        {
                            WriteToLog(MainForm.updateLogPath, "Possibly invalid manifest file, can't find URL tag in Assembly");
                        }

                        // Now the remaining files.
                        for (int i = 1; i < fileList.Length; ++i)
                        {
                            string fileMD5  = CalculateMD5(fileList[i]);
                            string fileName = Path.GetFileName(fileList[i]);

                            root.Add(new XElement("Name", new XAttribute("Value", fileName), new XElement("MD5", fileMD5)));
                        }

                        doc.Save(manifest);
                    }
                    else
                    {
                        WriteToLog(MainForm.updateLogPath, "Cannot find an assembly in the working path: " + workingPath);
                    }
                }
                else
                {
                    DialogResult d = TopMostMessageBox.Show(
                        true,
                        true,
                        "The manifest input directory does not contain any files, or cannot be created.\r\nPlease create the following directory and then confirm: " + workingPath,
                        "TD Helper - Error",
                        MessageBoxButtons.OKCancel);

                    if (d == DialogResult.OK)
                    {
                        GenerateManifest(workingPath, manifest, URL);
                    }
                }
            }
            catch (Exception e)
            {
                WriteToLog(MainForm.updateLogPath, e.Message);
            }
        }