Example #1
0
        private void ChangeIniValue(string serverName, string section, string key, string value)
        {
            //copy one copy to backup folder
            BackupFile(serverName);
            //update the temp file
            UpdateTmpFile(serverName);
            //Change the tmpFile using Normal ini function
            using (IniTools ini = new IniTools(tmpFile))
            {
                ini.WriteValue(section, key, value);
            }
            //Update the Original File
            string data;
            string originalFile = serverPrefix.Replace("{0}", serverName);

            using (StreamReader sr = new StreamReader(tmpFile, true))
            {
                data = sr.ReadToEnd();
                sr.Close();
                sr.Dispose();
            }
            using (StreamWriter sw = new StreamWriter(originalFile, false, new UTF8Encoding(true)))
            {
                sw.Write(data);
                sw.Flush();
                sw.Close();
            }
        }
Example #2
0
 private void UpdateIpRoomDict()
 {
     ipRoom = new Dictionary <int, string>();
     using (IniTools ini = new IniTools(tmpFile))
     {
         string room;
         for (int i = 1; i <= 255; i++)
         {
             room = ini.ReadValue("Room", "192.168.1." + i.ToString());
             if (room != "")
             {
                 ipRoom.Add(i, room);
             }
         }
     }
 }
Example #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            homeDIR = Directory.GetCurrentDirectory();

            backupDIR = Path.Combine(homeDIR, "backup");
            if (!Directory.Exists(backupDIR)) //if backup directory not found, just create one
            {
                Directory.CreateDirectory(backupDIR);
            }

            tmpDIR = Path.Combine(homeDIR, "tmp");
            if (!Directory.Exists(tmpDIR)) //if tmp directory not found, just create one
            {
                Directory.CreateDirectory(tmpDIR);
            }
            tmpFile = Path.Combine(tmpDIR, "tmp.ini");

            confFile = Path.Combine(homeDIR, "conf.ini");
            if (!File.Exists(confFile))
            {
                MessageBox.Show("缺少Conf.ini", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Application.Exit();
            }

            string timestring;

            using (IniTools ini = new IniTools(confFile))
            {
                serverNo = ini.ReadValue("Servers", "list").Split(new Char[] { ',' }); //get the server list seperate by ','
                string tmp = ini.ReadValue("AutoRest", "status");
                if (tmp.Equals("1"))
                {
                    autoReset = true;
                }
                timestring = ini.ReadValue("AutoRest", "time");
            }
            string[] tmpTime = timestring.Split(':');
            resetHour    = int.Parse(tmpTime[0]);
            resetMinutes = int.Parse(tmpTime[1]);

            if (autoReset)
            {
                timer1.Enabled = true; //start timer;
            }
            LoadRoomServerState();     // first page is Room Server
        }
Example #4
0
 private void UpdateRoomServerDict()
 {
     //get room data from ip, so need to update it first
     UpdateIpRoomDict();
     RoomServer = new Dictionary <string, string>();
     using (IniTools ini = new IniTools(tmpFile))
     {
         string server;
         foreach (string room in ipRoom.Values)
         {
             server = ini.ReadValue("TotalSelect", room);
             if ((server != "") && (!RoomServer.ContainsKey(room)))
             {
                 RoomServer.Add(room, server);
             }
         }
     }
 }
Example #5
0
        private void LoadScreenSaverSatus()
        {
            //update tmp file to server 2
#if DEBUG
            UpdateTmpFile(serverNo[0]); //using first file in the server list for debug
#else
            UpdateTmpFile("2");
#endif
            using (IniTools ini = new IniTools(tmpFile))
            {
                string status = ini.ReadValue("Conf", "ScreenSaver");
                if (status.Trim().Equals("1"))  //switch on screensaver
                {
                    checkBox1.Checked = false;
                }
                else
                {
                    checkBox1.Checked = true;
                }
            }
        }
Example #6
0
        private void LoadServerState()
        {
#if DEBUG
            UpdateTmpFile(serverNo[0]); //use first server in list for DEBUG purpose
#else
            UpdateTmpFile("2");         //update server2 is enough
#endif

            using (IniTools ini = new IniTools(tmpFile))
            {
                //use Normal ini tool to read it
                string state = ini.ReadValue("status", "state").Trim();
                switch (state)
                {
                case "1":
                    comboBox1.SelectedIndex = 0;
                    break;

                case "3":
                    comboBox1.SelectedIndex = 1;
                    break;

                case "6":
                    comboBox1.SelectedIndex = 2;
                    break;

                case "9":
                    comboBox1.SelectedIndex = 3;
                    break;

                case "10":
                    comboBox1.SelectedIndex = 4;
                    break;

                default:
                    break;
                }
            }
        }
Example #7
0
        private void ResetDefault()
        {
#if DEBUG
            string serverName = serverNo[0]; //use first server in list for DEBUG purpose
#else
            string serverName = "2";         //only server2 need to change
#endif
            //update the temp file
            UpdateTmpFile(serverName);
            //Reset Default ScreenSaver status
            string section = "Conf";
            string key     = "ScreenSaver";
            string value   = "1";
            using (IniTools ini = new IniTools(tmpFile))
            {
                //use Normal ini tool to read it
                value = ini.ReadValue(section, key).Trim();
            }
            if (!value.Equals("1"))
            {
                ChangeIniValue(serverName, section, key, "1");
            }

            //Reset Default Status
            section = "status";
            key     = "state";
            value   = "1";
            using (IniTools ini = new IniTools(tmpFile))
            {
                //use Normal ini tool to read it
                value = ini.ReadValue(section, key).Trim();
            }
            if (!value.Equals("1"))
            {
                ChangeIniValue(serverName, section, key, "1");
            }

            //Reset Room Server To Default
            Dictionary <string, string> RoomServerNeedChange = new Dictionary <string, string>(); //room-server key-value pair need to change
            section = "DefaultRoomStatus";
            key     = "";
            value   = "";
            foreach (string room in RoomServer.Keys)
            {
                //read the default and compare with exist value
                using (IniTools ini = new IniTools(confFile))
                {
                    //use Normal ini tool to read it
                    value = ini.ReadValue(section, room).Trim();
                }
                if (value.Equals("")) // not exist in default, no change
                {
                    continue;
                }
                if (value.Equals(RoomServer[room])) //exists amd same as now, no change
                {
                    continue;
                }
                RoomServerNeedChange.Add(room, value); // add to list for change
            }
            //修改要改房
            section = "TotalSelect";
            foreach (string room in RoomServerNeedChange.Keys)
            {
                foreach (string server in serverNo)
                {
                    //修改新值
                    ChangeIniValue(server, section, room, RoomServerNeedChange[room]);
                }
            }
            //Update new ServerRoom
            LoadRoomServerState();
        }