Exemplo n.º 1
0
    //Get setting file from default setting file path and set it to GlobalInfo
    public static void GetSettingFileAndSet()
    {
        if (File.Exists(GlobalInfo.DEFAULT_SETTING_PATH + GlobalInfo.DEFAULT_SETTING_FILE_NAME))
        {
            FileStream         fs            = File.Open(GlobalInfo.DEFAULT_SETTING_PATH + GlobalInfo.DEFAULT_SETTING_FILE_NAME, FileMode.Open);
            XmlSerializer      xmlSerializer = new XmlSerializer(typeof(GlobalInfo.Setting));
            XmlReader          reader        = XmlReader.Create(fs);
            GlobalInfo.Setting data          = xmlSerializer.Deserialize(reader) as GlobalInfo.Setting;
            fs.Close();

            GlobalInfo.G_necessaryTime = data.necessaryTime;
            GlobalInfo.G_speed         = data.speed;
            GlobalInfo.G_playerDelay   = data.delay;
        }
        else
        {
            GlobalInfo.Setting tempSetting = new GlobalInfo.Setting();
            tempSetting.delay          = 0.0f;
            tempSetting.necessaryTime  = 2.0f;
            tempSetting.speed          = GlobalInfo.DEFAULT_DISTANCE / tempSetting.necessaryTime;
            GlobalInfo.G_necessaryTime = tempSetting.necessaryTime;
            GlobalInfo.G_speed         = tempSetting.speed;
            GlobalInfo.G_playerDelay   = tempSetting.delay;
            SaveSettingToFile(ref tempSetting);
        }
    }
Exemplo n.º 2
0
    //call when setting file is changed
    public static void SaveSettingToFile(ref GlobalInfo.Setting tempSetting)
    {
        CheckDirectory(GlobalInfo.DEFAULT_SETTING_PATH);
        string fullSavePath = GlobalInfo.DEFAULT_SETTING_PATH + GlobalInfo.DEFAULT_SETTING_FILE_NAME;

        FileStream fs;

        // Create a file or open an old one up for writing to
        fs = File.Open(fullSavePath, FileMode.OpenOrCreate);

        XmlSerializer serializer = new XmlSerializer(typeof(GlobalInfo.Setting));
        TextWriter    textWriter = new StreamWriter(fs);

        serializer.Serialize(textWriter, tempSetting);
        fs.Close();
    }