Ejemplo n.º 1
0
        internal static ProgramSettingsData fromString(string s)
        {
            string[] parts         = s.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            int      filterCount   = 0;
            DateTime lastCheckDate = new DateTime(2015, 1, 1);

            if (parts != null && parts.Length == 2)
            {
                Int32.TryParse(parts[0], out filterCount);
                DateTime.TryParseExact(
                    parts[1],
                    "yyyy-MM-dd",
                    null /*provider*/,
                    System.Globalization.DateTimeStyles.None,
                    out lastCheckDate);
            }

            ProgramSettingsData returnValue = new ProgramSettingsData
            {
                FilterCount     = filterCount,
                DateLastUpdated = lastCheckDate
            };

            return(returnValue);
        }
Ejemplo n.º 2
0
        private static void LoadOrSaveProgramSettings(bool load)
        {
            if (AppDataFileName == null)
            {
                string folderName = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                folderName = Path.Combine(folderName, "TouchpadPeace");
                if (!Directory.Exists(folderName))
                {
                    try { Directory.CreateDirectory(folderName); }
                    catch { }

                    FirstRun = true;
                }

                AppDataFileName = Path.Combine(folderName, "TouchpadPeaceData.txt");
            }

            if (load)
            {
                String fileContents = "0";
                bool   fileExists   = File.Exists(AppDataFileName);
                if (fileExists)
                {
                    try
                    {
                        fileContents = File.ReadAllText(AppDataFileName);
                    }
                    catch (Exception)
                    {
                        fileExists = false;
                    }
                }
                else
                {
                    FirstRun = true;
                }

                ProgramSettings = ProgramSettingsData.fromString(fileContents);

                if (!fileExists)
                {
                    LoadOrSaveProgramSettings(false /*load*/);
                }
            }
            else
            {
                try
                {
                    File.WriteAllText(AppDataFileName, ProgramSettings.ToString());
                }
                catch (Exception)
                {
                }
            }
        }