/// <summary>
        /// Prompts the user if input path is invalid, and creates a new folder in the executing directory if no choice is made by the user. Finds/creates subfolders corresponding to saveType and date.
        /// </summary>
        /// <param name="path">A path to CiceroBackupSettings. Will be checked for validity.</param>
        /// <param name="saveType">What type of data will be saved in this folder.</param>
        /// <param name="date">The date this data will be saved in.</param>
        /// <returns>A valid path that can be used to store data, or null if it was unable to do so.</returns>
        private static string CorrectPath(string path, SaveType saveType, DateTime date)
        {
            if (!Path.IsPathRooted(path) || !path.EndsWith("CiceroBackupSettings"))
            {
                //If the path is incorrect for some reason, ask the user to supply a path
                path = MainClientForm.PromptUserForSavePath();

                //If this lowlife still won't supply a valid path, create a subfolder in the Cicero
                //directory, which is more than this nerf-herder deserves
                if (path == null || !Path.IsPathRooted(path) || !path.EndsWith("CiceroBackupSettings"))
                {
                    path = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase);
                    path = Path.Combine(path, "CiceroBackupSettings");
                }
            }

            //Now that we know the path correctly points to the CiceroBackupSettings folder, use saveType and date
            //to specify the correct folder for what we will be saving
            path = Path.Combine(path, date.Year.ToString());
            path = Path.Combine(path, MonthToName(date.Month));
            path = Path.Combine(path, date.Day.ToString());
            path = Path.Combine(path, saveType.ToString());

            try
            {
                Directory.CreateDirectory(path); //Automatically creates all subdirectories unless they already exist
            }
            catch (Exception e)
            {
                //MessageBox.Show("Attempted to create a directory in " + path + ", but the process failed: " + e.ToString());
                path = null;
            }

            return(path);
        }
Ejemplo n.º 2
0
        public static void runCicero(RunLog runLog)
        {
            try
            {
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
                Application.EnableVisualStyles();

                // Detect if Windows 7 or Vista is being used.
                OperatingSystem osInfo = System.Environment.OSVersion;
                if (osInfo.Version.Major == 6)
                {
                    WordGenerator.GlobalInfo.usingWindows7 = true;
                }



                try
                {
                    Application.SetCompatibleTextRenderingDefault(false);
                }
                catch (InvalidOperationException)
                {
                }


                MainClientForm mainForm;

                if (runLog == null)
                {
                    mainForm = new MainClientForm();
                }
                else
                {
                    mainForm = new MainClientForm(runLog);
                }

                ClientRunner runner = new ClientRunner();

                runner.messageLog += new EventHandler <MessageEvent>(mainForm.addMessageLogText);
                Storage.registerMessageLogHandler(mainForm.handleMessageEvent);

                Application.Run(mainForm);
            }
            catch (Exception e)
            {
                display_unhandled_exception(e);
            }
        }