Exemplo n.º 1
0
        public static void Load()
        {
            Instance.Config = new Instance.config();
            var emptyjson = JsonConvert.SerializeObject(
                new ConfigJsonData {
                GameDirectory = string.Empty, Admin = string.Empty
            });

            if (Directory.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "/config/"))
            {
                if (File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "/config/config.json"))
                {
                    CurrentConfig = JsonConvert.DeserializeObject <ConfigJsonData>(
                        File.ReadAllText(Path.GetDirectoryName(Application.ExecutablePath) + "/config/config.json"));
                    Instance.Config.Admin = CurrentConfig.Admin;
                }
                else
                {
                    File.WriteAllText(
                        Path.GetDirectoryName(Application.ExecutablePath) + "/config/config.json",
                        emptyjson);

                    MessageBox.Show("Please set the game directory", "Error");
                }
            }
            else
            {
                Directory.CreateDirectory(Path.GetDirectoryName(Application.ExecutablePath) + "/config/");
                File.WriteAllText(Path.GetDirectoryName(Application.ExecutablePath) + "/config/config.json", emptyjson);
                MessageBox.Show("Please set the game directory", "Error");
            }

            if (CurrentConfig.GameDirectory == string.Empty)
            {
                MessageBox.Show("Please set the game directory", "Error");
            }

            if (CurrentConfig.Buttons == null)
            {
                CurrentConfig.Buttons         = new Buttons();
                CurrentConfig.Buttons.buttons = new List <BindsViewModel>(10);
                for (int i = 0; i < 10; i++)
                {
                    CurrentConfig.Buttons.buttons.Add(new BindsViewModel()
                    {
                        Id         = i,
                        BindType   = "LocalMusic",
                        IsSelected = true,
                        Link       = string.Empty,
                        NumpadKey  = "NUMPAD " + i
                    });
                }
            }
            Instance.Config.Admin                  = CurrentConfig.Admin;
            Instance.Config.GameDir                = CurrentConfig.GameDirectory;
            Instance.Config.MaximumParsesPerMin    = CurrentConfig.AntiSpamThredshold;
            Instance.Config.MaximumBackgroundInMin = CurrentConfig.MaximumBackgroundInMin;
            Instance.Config.BaseVolume             = CurrentConfig.BaseVolume;
            AppConfig.Save();
        }
Exemplo n.º 2
0
        public static void Load()
        {
            var emptyjson = JsonConvert.SerializeObject(
                new ConfigJsonData {
                GameDirectory = string.Empty, Admin = string.Empty
            });

            if (Directory.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "/config/"))
            {
                if (File.Exists(Path.GetDirectoryName(Application.ExecutablePath) + "/config/config.json"))
                {
                    CurrentConfig = JsonConvert.DeserializeObject <ConfigJsonData>(
                        File.ReadAllText(Path.GetDirectoryName(Application.ExecutablePath) + "/config/config.json"));
                    Instance.Config.Admin = CurrentConfig.Admin;
                }
                else
                {
                    File.WriteAllText(
                        Path.GetDirectoryName(Application.ExecutablePath) + "config/config.json",
                        emptyjson);

                    new RequestifyTF2GUI.MessageBox.MessageBox().Show("Please set the game directory", "Error",
                                                                      RequestifyTF2GUI.MessageBox.MessageBox.Sounds.Exclamation);
                }
            }
            else
            {
                Directory.CreateDirectory(Path.GetDirectoryName(Application.ExecutablePath) + "/config/");
                File.WriteAllText(Path.GetDirectoryName(Application.ExecutablePath) + "/config/config.json", emptyjson);
                new RequestifyTF2GUI.MessageBox.MessageBox().Show("Please set the game directory", "Error",
                                                                  RequestifyTF2GUI.MessageBox.MessageBox.Sounds.Exclamation);
            }

            if (CurrentConfig.GameDirectory == string.Empty)
            {
                new RequestifyTF2GUI.MessageBox.MessageBox().Show("Please set the game directory", "Error",
                                                                  RequestifyTF2GUI.MessageBox.MessageBox.Sounds.Exclamation);
            }

            Instance.Config.GameDir = CurrentConfig.GameDirectory;
        }
	public void saveAllData()
	{
		Debug.Log(" saveAll" + myDict);
		foreach (string item in myDict.Keys) {
			 DetalItem ite1;
			myDict.TryGetValue(item,out ite1);
			Debug.Log(" string key " + item + " value " + ite1.centerX);
		}

//		Dictionary<string,ConfigJsonData>dict =new Dictionary<string,ConfigJsonData>();

		ConfigJsonData jsonData = new ConfigJsonData();
		jsonData.errMsg = "";
		jsonData.errCode = 0;
		jsonData.version = VersionInputObj.transform.FindChild("Text").gameObject.GetComponent<Text>().text;



		Config config = new Config();


		config.bluetoothEnabled = BluethObj.GetComponent<Toggle>().isOn;
		config.accelerometerEnabled = JiashujiObj.GetComponent<Toggle>().isOn;
		config.gyroscopeEnabled = TuoluoyiObj.GetComponent<Toggle>().isOn;
		config.packageName = PackageInputObj.transform.FindChild("Text").gameObject.GetComponent<Text>().text;

		InfoConfig info = new InfoConfig();


	

	

		if (YaoganObj.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(YaoganObj.tag, out info.padControll);
//			config.infoConfig.set((object)info.padControll,YaoganObj.tag);
			config.infoConfig.Add(YaoganObj.tag,info.padControll);
		}

		if (AToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(AToggle.tag, out info.aBt);
//			jsonData.config.SetValue(info.aBt, AToggle.tag);
			config.infoConfig.Add(AToggle.tag, info.aBt);
		}
		if (BToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(BToggle.tag, out info.bBt);
//			jsonData.config.SetValue(info.bBt, BToggle.tag);
			config.infoConfig.Add(BToggle.tag,info.bBt);
		}

		if (CToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(CToggle.tag, out info.cBt);
//			jsonData.config.SetValue((object)info.cBt, CToggle.tag);
			config.infoConfig.Add(CToggle.tag, info.cBt);
		}

		if (DToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(DToggle.tag, out info.dBt);
//			jsonData.config.SetValue((object)info.dBt, DToggle.tag);
			config.infoConfig.Add(DToggle.tag,info.dBt);

		}
		if (EToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(EToggle.tag, out info.eBt);
//			jsonData.config.SetValue((object)info.eBt, EToggle.tag);
			config.infoConfig.Add(EToggle.tag, info.eBt);
		}
		if (FToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(FToggle.tag, out info.fBt);
//			jsonData.config.SetValue((object)info.fBt, FToggle.tag);
			config.infoConfig.Add(FToggle.tag, info.fBt);
		}
		if (GToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(GToggle.tag, out info.gBt);
//			jsonData.config.SetValue((object)info.gBt, GToggle.tag);
			config.infoConfig.Add(GToggle.tag, info.gBt);
		}
		if (HToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(HToggle.tag, out info.hBt);
//			jsonData.config.SetValue((object)info.hBt, HToggle.tag);
			config.infoConfig.Add(HToggle.tag, info.hBt);
		}
		if (IToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(IToggle.tag, out info.iBt);
//			jsonData.config.SetValue((object)info.iBt, IToggle.tag);
			config.infoConfig.Add(IToggle.tag,info.iBt);
		}
		if (LToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(LToggle.tag, out info.lBt);
//			jsonData.config.SetValue((object)info.lBt, LToggle.tag);
			config.infoConfig.Add(LToggle.tag, info.lBt);
		}
		if (MToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(MToggle.tag, out info.mBt);
			config.infoConfig.Add(MToggle.tag,info.mBt);
		}
		if (NToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(NToggle.tag, out info.iBt);
			config.infoConfig.Add(NToggle.tag, info.iBt);
		}
		if (OToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(OToggle.tag, out info.oBt);
			config.infoConfig.Add(OToggle.tag, info.oBt);
		}
		if (PToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(PToggle.tag, out info.pBt);
			config.infoConfig.Add(PToggle.tag, info.pBt);
		}
		if (JToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(JToggle.tag, out info.jBt);
			config.infoConfig.Add( JToggle.tag, info.jBt);
		}
		if (KToggle.GetComponent<Toggle>().isOn) {
			myDict.TryGetValue(KToggle.tag, out info.kBt);
			config.infoConfig.Add( KToggle.tag, info.kBt);
		}

//		config.infoConfig = info;

		jsonData.config = new Config[1];
		jsonData.config[0] = config;

		JsonData map = JsonMapper.ToJson(jsonData);

//		fsDirectConverter con = new fsDirectConverter();
//		con.TrySerialize();




		Debug.Log(" save "+ myDict.ToString() + " " + jsonData   + map);
	}