예제 #1
0
        public static int Main(String[] arguments)
        {
            try {
                                #if DEBUG
                ConsoleTraceListener consoleTraceListener = new ConsoleTraceListener(true);
                Debug.Listeners.Add(consoleTraceListener);
                                #endif

                Application.EnableVisualStyles();

                using (MainForm mainForm = new MainForm()) {
                    Application.Run(mainForm);
                }

                                #if DEBUG
                Debug.Listeners.Remove(consoleTraceListener);
                                #endif
            }
            catch (Exception exception) {
                                #if DEBUG
                Console.Error.WriteLine("Error: exception: {0}", exception);
                                #endif

                MessageBoxes.error(exception.Message);

                return(1);
            }
            return(0);
        }
예제 #2
0
        private static Configuration tryLoadConfiguration()
        {
            try {
                Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);

                ExeConfigurationFileMap exeConfigurationFileMap = new ExeConfigurationFileMap();
                exeConfigurationFileMap.ExeConfigFilename = configuration.FilePath;

                                #if DEBUG
                Console.WriteLine("Configuration file: {0}", configuration.FilePath);
                                #endif

                configuration = ConfigurationManager.OpenMappedExeConfiguration(exeConfigurationFileMap, ConfigurationUserLevel.None);

                configuration.AppSettings.Settings

                .take("epubViewerProgramFilePath", out epubViewerProgramFilePath, getCommonEpubViewerProgramFilePathOrNull)
                .take("epubViewerOpenArgumentFormatString", out epubViewerOpenArgumentFormatString, defaultArgumentFormatString)
                .take("epubViewerOpenToSectionArgumentFormatString", out epubViewerOpenToSectionArgumentFormatString,
                      () => isMostLikelyCalibre2(epubViewerProgramFilePath) ? "--open-at toc:\"{1}\" \"{0}\"" : defaultArgumentFormatString
                      )

                .take("wordViewerProgramFilePath", out wordViewerProgramFilePath, getCommonWordViewerProgramFilePathOrNull)
                .take("wordViewerOpenArgumentFormatString", out wordViewerOpenArgumentFormatString, defaultArgumentFormatString)

                .take("pdfViewerProgramFilePath", out pdfViewerProgramFilePath, getCommonPdfViewerProgramFilePathOrNull)
                .take("pdfViewerOpenArgumentFormatString", out pdfViewerOpenArgumentFormatString, defaultArgumentFormatString)
                .take("pdfViewerOpenToPageArgumentFormatString", out pdfViewerOpenToPageArgumentFormatString,
                      () => isMostLikelyAdobeAcrobatReaderDC(pdfViewerProgramFilePath) ? "page={1} \"{0}\"" : defaultArgumentFormatString
                      )

                .take("downloadsDirectoryPath", out downloadsDirectoryPath, getUserDownloadsDirectoryPathOrUserProfileDirectoryPath)
                .take("startingDirectoryPath", out startingDirectoryPath, () => Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))

                .take("ouUsername", out ouUsername)
                .take("ouPassword", out ouPasswordEncrypted);

                return(configuration);
            }
            catch (Exception exception) {
                Console.Error.WriteLine("Error: could not load program settings due to exception: {0}", exception);
                MessageBoxes.error("Could not load program settings");
                return(null);
            }
        }
예제 #3
0
        private void browseForDirectoryPathToUpdate(TextBox textBox)
        {
            try {
                using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog()
                {
                    SelectedPath = !String.IsNullOrWhiteSpace(textBox.Text) ?
                                   textBox.Text :
                                   Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
                }) {
                    if (DialogResult.OK == folderBrowserDialog.ShowDialog(this))
                    {
                        textBox.Text = folderBrowserDialog.SelectedPath;
                    }
                }
            }
            catch (Exception exception) {
                                #if DEBUG
                Console.Error.WriteLine("Error: exception: {0}", exception);
                                #endif

                MessageBoxes.error(exception.Message);
            }
        }
예제 #4
0
 private static void trySaveConfiguration(Configuration configuration)
 {
     try {
         configuration.AppSettings.Settings
         .with("epubViewerProgramFilePath", epubViewerProgramFilePath)
         .with("epubViewerOpenArgumentFormatString", epubViewerOpenArgumentFormatString)
         .with("epubViewerOpenToSectionArgumentFormatString", epubViewerOpenToSectionArgumentFormatString)
         .with("wordViewerProgramFilePath", wordViewerProgramFilePath)
         .with("wordViewerOpenArgumentFormatString", wordViewerOpenArgumentFormatString)
         .with("pdfViewerProgramFilePath", pdfViewerProgramFilePath)
         .with("pdfViewerOpenArgumentFormatString", pdfViewerOpenArgumentFormatString)
         .with("pdfViewerOpenToPageArgumentFormatString", pdfViewerOpenToPageArgumentFormatString)
         .with("downloadsDirectoryPath", downloadsDirectoryPath)
         .with("startingDirectoryPath", startingDirectoryPath)
         .with("ouUsername", ouUsername)
         .with("ouPassword", ouPasswordEncrypted);
         configuration.Save(ConfigurationSaveMode.Full);
     }
     catch (Exception exception) {
         // suppress any errors, the program is exiting not much can be done here
         Console.Error.WriteLine("Error: could not save program settings due to exception: {0}", exception);
         MessageBoxes.error(String.Format("Could not save program settings due to exception: {0}", exception));
     }
 }
예제 #5
0
        private void browseForProgramFilePathToUpdate(TextBox textBox)
        {
            try {
                using (OpenFileDialog openFileDialog = new OpenFileDialog()
                {
                    Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*",
                    InitialDirectory = !String.IsNullOrWhiteSpace(textBox.Text) ?
                                       Path.GetDirectoryName(textBox.Text) ?? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) :
                                       Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
                }) {
                    if (DialogResult.OK == openFileDialog.ShowDialog(this))
                    {
                        textBox.Text = openFileDialog.FileName;
                    }
                }
            }
            catch (Exception exception) {
                                #if DEBUG
                Console.Error.WriteLine("Error: exception: {0}", exception);
                                #endif

                MessageBoxes.error(exception.Message);
            }
        }