public static bool SetSettingValueFromFile() { StreamReader streamReader = (StreamReader)null; try { string path = Path.Combine("C:\\Users", Environment.UserName, "AppData\\Local\\ScreenShot", "Save.txt"); if (!File.Exists(path)) { return(false); } streamReader = new StreamReader(path); string str = streamReader.ReadLine(); streamReader.Close(); if (str == null) { ScreenShortClass.SaveSettingValueToFile(); return(true); } string[] strArray = str.Split("|".ToCharArray()); if (strArray.Length != 3) { return(false); } Settings.Default.SleepTime = Convert.ToInt32(strArray[0]); Settings.Default.SaveToClipboard = Convert.ToBoolean(strArray[1]); Settings.Default.PenWidth = Convert.ToInt32(strArray[2]); return(true); } catch (Exception ex) { streamReader?.Close(); return(false); } }
public static bool LoadFromFile() { try { string str = Path.Combine("C:\\Users", Environment.UserName, "AppData\\Local", "ScreenShot"); Directory.CreateDirectory(str); if (File.Exists(Path.Combine(str, "Save.txt"))) { ScreenShortClass.SetSettingValueFromFile(); } else { ScreenShortClass.SaveSettingValueToFile(); } return(true); } catch (Exception ex) { return(false); } }