Esempio n. 1
0
        private void ReadBookmarks()
        {
            if (!JsonUtility.PopulateFromFile(pathFormatter.GetConfiguration("bookmark-folders"), bookmarksModel.BookmarkFolders))
            {
                JsonUtility.PopulateFromFile(pathFormatter.GetDefaultConfiguration("bookmark-folders"), bookmarksModel.BookmarkFolders);
            }

            JsonUtility.PopulateFromFile(pathFormatter.GetConfiguration("bookmarks"), bookmarksModel.Bookmarks);
        }
Esempio n. 2
0
        private bool ReadTags()
        {
            string cachedTagsFilePath = pathFormatter.GetConfiguration("tags");

            JsonUtility.PopulateFromFile(cachedTagsFilePath, tagsModel.AllTags);

            if (tagsModel.AllTags != null)
            {
                foreach (TagInfo tag in tagsModel.AllTags)
                {
                    tag.Name = tag.Name.Replace('-', ' ');
                }
            }

            return(true);
        }
Esempio n. 3
0
 private void ReadSearchHistory()
 {
     JsonUtility.PopulateFromFile(pathFormatter.GetConfiguration("searches"), browsingModel.SearchHistory);
 }
Esempio n. 4
0
 private void ReadHidelist()
 {
     JsonUtility.PopulateFromFile(pathFormatter.GetConfiguration("hidelist"), metadataKeywordLists.Hidelist);
 }
Esempio n. 5
0
 private void ReadTheme()
 {
     JsonUtility.PopulateFromFile(pathFormatter.GetConfiguration("theme"), theme);
 }
Esempio n. 6
0
File: Program.cs Progetto: NHxD/NHxD
        private static void Main()
        {
            try
            {
                string assemblyLocation  = Assembly.GetEntryAssembly().Location;
                string assemblyDirectory = Path.GetDirectoryName(assemblyLocation).Replace('\\', '/');

                ApplicationPath = assemblyDirectory;
                SourcePath      = Directory.GetCurrentDirectory();

                Directory.SetCurrentDirectory(ApplicationPath);

                StartupSettings = JsonUtility.LoadFromFile <Configuration.StartupSettings>(assemblyDirectory + "/assets/defaults/startup.json") ?? new Configuration.StartupSettings();

                if (string.IsNullOrEmpty(StartupSettings.SettingsPath))
                {
                    StartupSettings.SettingsPath = "{SpecialFolder.MyDocuments}/NHxD/user/";
                }

                {
                    PathFormatter pathFormatter = new PathFormatter(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), Directory.GetCurrentDirectory(), null, null, null, false);

                    Settings = new Configuration.Settings();
                    JsonUtility.PopulateFromFile(pathFormatter.GetPath(StartupSettings.SettingsPath + "/settings.json"), Settings);

                    // always override settings paths.
                    if (Settings.PathFormatter != null)
                    {
                        Settings.PathFormatter.Custom["DefaultSettingsPath"] = StartupSettings.DefaultSettingsPath;
                        Settings.PathFormatter.Custom["SettingsPath"]        = StartupSettings.SettingsPath;
                    }
                }

                string    currentProcessName = Process.GetCurrentProcess().ProcessName;
                Process[] activeProcesses    = Process.GetProcessesByName(currentProcessName);

                if (!Settings.Process.AllowMultipleInstances &&
                    activeProcesses.Length > 1)
                {
                    IntPtr hWnd = IntPtr.Zero;

                    hWnd = activeProcesses[0].MainWindowHandle;
                    User32.NativeMethods.ShowWindowAsync(new HandleRef(null, hWnd), User32.NativeMethods.SW_RESTORE);
                    User32.NativeMethods.SetForegroundWindow(activeProcesses[0].MainWindowHandle);

                    return;
                }

                InstanceIndex = activeProcesses.Length - 1;

                if (Settings.Eula.CheckLegalAge)
                {
                    DialogResult dialogResult = MessageBox.Show("If you are under the age of 18 years, or under the age of majority in the location from where you are launching this program, you do not have authorization or permission to use this program or access any of its materials.\r\n\r\nBy clicking on the \"Yes\" button, you agree and certify under penalty of perjury that you are an adult.", "End-User License Agreement", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                    if (dialogResult != DialogResult.Yes)
                    {
                        return;
                    }

                    Settings.Eula.CheckLegalAge = false;
                }

                if (Settings.Eula.PleadArtistSupport)
                {
                    MessageBox.Show("If you find something you really like, please consider buying a copy to support the artist!", "NHxD", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    Settings.Eula.PleadArtistSupport = false;
                }

                if (Settings.Log.Filters != LogFilters.None)
                {
                    PathFormatter PathFormatter = new PathFormatter(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), Directory.GetCurrentDirectory(), Settings.PathFormatter.Custom, Settings.PathFormatter, Settings.Lists.Tags.LanguageNames, Settings.PathFormatter.IsEnabled);
                    string        logPath       = Settings.Log.KeepSeparateLogs ? PathFormatter.GetLog(DateTime.Now) : PathFormatter.GetLog();

                    if (Settings.Log.Overwrite &&
                        File.Exists(logPath))
                    {
                        File.WriteAllText(logPath, "");
                    }

                    Logger = new Logger(logPath, Settings.Log.Filters);

                    FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);

                    Logger.WriteSeparator('=');
                    Logger.WriteLineFormat("{0} version {1}", fileVersionInfo.ProductName, fileVersionInfo.FileVersion);
                    Logger.WriteLine(DateTime.Now.ToString(CultureInfo.InvariantCulture));
                    Logger.WriteSeparator('=');
                }
                else
                {
                    Logger = new Logger();
                }

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
            catch (Exception ex)
            {
#if DEBUG
                if (MessageBox.Show("Debug?" + Environment.NewLine + Environment.NewLine + ex.ToString(), "Un unhandled exception occured.", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                {
                    throw;
                }
#else
                MessageBox.Show(ex.ToString(), "Un unhandled exception occured.", MessageBoxButtons.OK, MessageBoxIcon.Error);
#endif
            }
        }