Ejemplo n.º 1
0
        private void save()
        {
            String str = "{ \"settings\":{";

            str += "\"serverip\":\"";
            str += Settings.serverIpAddress;
            str += "\"";

            str += ",\"port\":";
            str += Settings.serverPort;

            str += "}";

            str += ",\"shields\":";

            String jsonarray = "[";
            int    i         = 0;

            foreach (Shield shield in shields.shieldList)
            {
                String json = shield.getShieldJSON();

                if (i++ != 0)
                {
                    jsonarray += ",";
                }
                jsonarray += json;
            }
            jsonarray += "]";

            str += jsonarray + "}";

            try
            {
                System.IO.FileStream wFile;
                byte[] byteData = null;
                byteData = Encoding.ASCII.GetBytes(str);

                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                wFile = new FileStream(fileName, FileMode.CreateNew);
                wFile.Write(byteData, 0, byteData.Length);
                wFile.Close();
            }
            catch (IOException ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }