コード例 #1
0
        public static ConfigurationData Read()
        {
            try
            {
                config = new ConfigurationData();
                siteUpdatedDates.Clear();

                string folder = AppDomain.CurrentDomain.BaseDirectory + "data";
                Directory.CreateDirectory(folder);

                string configPath = folder + "\\configuration";
                using (StreamReader sr = new StreamReader(configPath, Encoding.UTF8))
                {
                    while (!sr.EndOfStream)
                    {
                        string   line  = sr.ReadLine();
                        string[] parts = line.Split('=');
                        if (parts.Length == 2)
                        {
                            if (parts[0] == CLIENT_ID)
                            {
                                config.ClientID = parts[1];
                            }
                            else if (parts[0] == TOTAL_WORKERS)
                            {
                                config.TotalConcurrentWorkers = int.Parse(parts[1]);
                            }
                            else if (parts[0] == SHORTCUT)
                            {
                                config.AutoCreateShortcut = ConvertToBoolean(parts[1], true);
                            }
                            else if (parts[0] == ZIP)
                            {
                                config.AutoCreateZip = ConvertToBoolean(parts[1], false);
                            }
                            else if (parts[0] == PDF)
                            {
                                config.AutoCreatePdf = ConvertToBoolean(parts[1], false);
                            }
                            else if (parts[0] == CLEANUP)
                            {
                                config.AutoCleanup = ConvertToBoolean(parts[1], false);
                            }
                            else if (parts[0] == SHUTDOWN)
                            {
                                config.AutoShutdown = ConvertToBoolean(parts[1], false);
                            }
                            else if (parts[0] == DOWNLOAD_FOLDER)
                            {
                                config.DownloadFolder = parts[1];
                            }
                            else if (parts[0] == SHOW_TASKBAR_INFO)
                            {
                                config.ShowTaskbarInfoOnMinimize = ConvertToBoolean(parts[1], true);
                            }
                            else if (parts[0] == IGNORE_VERSION)
                            {
                                config.IgnoreVersion = parts[1];
                            }
                            else if (parts[0] == MINIMIZE_TASKBAR)
                            {
                                config.MinimizeTaskbar = ConvertToBoolean(parts[1], true);
                            }
                            else if (parts[0] == UPDATE_AFTER)
                            {
                                config.UpdateAfter = int.Parse(parts[1]);
                            }

                            foreach (MangaSite ms in Enum.GetValues(typeof(MangaSite)))
                            {
                                if (ms.ToString().Equals(parts[0], StringComparison.CurrentCultureIgnoreCase))
                                {
                                    DateTime dt = DateTime.ParseExact(parts[1], "yyyyMMdd", CultureInfo.CurrentCulture);
                                    siteUpdatedDates.Add(ms, dt);
                                }
                            }
                        }
                    }
                    sr.Close();
                }
            }
            catch { }

            return(new ConfigurationData(config));
        }