private StartUpState ReadDefaultSusFile() { BinaryFormatter bf = new BinaryFormatter(); StartUpState tempSus = new StartUpState(); try { using (Stream fStream = new FileStream(wesus, FileMode.Open, FileAccess.Read, FileShare.None )) { object obj; obj = bf.Deserialize(fStream); fStream.Close(); if (obj is StartUpState) { tempSus = (StartUpState)obj; } } } catch (Exception e) { Debug.WriteLine("~~ ERROR ~~"); Debug.WriteLine(e.Message); } return tempSus; }
private bool WriteDefaultSusFile() { BinaryFormatter bf = new BinaryFormatter(); bool sucessful = false; StartUpState tempSus = new StartUpState(false, null, true, true, videoSplashDefaultFile); try { using (Stream fStream = new FileStream(wesus, FileMode.Create, FileAccess.Write, FileShare.None )) { bf.Serialize(fStream, tempSus); sucessful = true; fStream.Close(); } } catch (Exception e) { Debug.WriteLine(e.ToString()); } return sucessful; }
public void Initialize() { /*this is bad style, I couldn't get the structure to properly use * automatic properties and constructor */ sus = new StartUpState(false, null); if(File.Exists(wesus)) { sus = ReadDefaultSusFile(); if (sus.UseCustomConfigFile) // use user-def config file { userConfigFilePath = sus.CustomConfigFilePath; currConfigs = ReadFromConfigFile(userConfigFilePath); } else // use default config file { currConfigs = ReadFromConfigFile(); } if (sus.PlaySpashScreen) // splash screen will be added to screenmanager { splashFilePath = sus.SplashScreenFilePath; } } else // file doesn't exist, set to default { WriteDefaultSusFile(); currConfigs = WriteDefaultConfigs(); } }