示例#1
0
        /// <summary>
        /// Load settings
        /// </summary>
        public static void Load()
        {
            filePath = Directory.GetCurrentDirectory() + @"\Plugins\KanColleCacher.ini";

            if (!File.Exists(filePath))
            {
                var path = Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                    "grabacr.net",
                    "KanColleViewer",
                    "KanColleCacher.ini"
                    );
                if (File.Exists(path))
                {
                    filePath = path;
                }
            }

            if (File.Exists(filePath))
            {
                var _Parser = ConfigParser.ReadIniFile(filePath);
                Current = _Parser.DeserializeObject <Settings>("Settings");

                try
                {
                    Directory.CreateDirectory(Current.CacheFolder);
                }
                catch (Exception ex)
                {
                    Current.CacheFolder = Directory.GetCurrentDirectory() + @"\MyCache";
                    Log.Exception(ex.InnerException, ex, "Cannot find or create MyCache folder");
                }
            }
            else
            {
                //设置文件丢失
                try
                {
                    Current = new Settings();
                    if (!Directory.Exists(Current.CacheFolder))
                    {
                        Directory.CreateDirectory(Current.CacheFolder);
                    }
                    Save();
                }
                catch (Exception ex)
                {
                    Log.Exception("Settings.Load()", ex, "Current.new !ERROR");
                    Debug.WriteLine(ex);
                }
            }

            try
            {
                Debug.WriteLine("Settings.Current.CacheFolder = " + Current.CacheFolder);
            }
            catch (Exception ex)
            {
                Log.Exception("Settings.Load()", ex, "Current== null");
                Debug.WriteLine(ex);
            }
            Current = Current ?? new Settings();
            Debug.Flush();
        }