コード例 #1
0
 public static void Load(string path)
 {
     ClearGraphics(GraphicController.rootList);
     GraphicController.Selected = null;
     try
     {
         if (File.Exists(path))
         {
             using (StreamReader sr = new StreamReader(path))
             {
                 GraphicSerializer serializer = new GraphicSerializer();
                 GraphicController.rootList = serializer.Deserialize(sr.ReadToEnd());
                 HideGraphics(GraphicController.rootList);
                 ControllerHelpers.CheckResize();
                 ControllerHelpers.RepositionControls(GraphicController.rootList);
                 CustomMessageBox.Show("Config file read.");
             }
         }
         else
         {
             CustomMessageBox.Show("No config file found.");
         }
     }
     catch { }
 }
コード例 #2
0
        public void Copy()
        {
            GraphicSerializer serializer = new GraphicSerializer();
            JObject           copy       = serializer.SerializeSingle(this, true);

            serializer.DeserializeSingle(copy);
            ControllerHelpers.CheckResize();
            ControllerHelpers.RepositionControls(rootList);
        }
コード例 #3
0
 public static void Save(string folderName)
 {
     try
     {
         // Create Config folder if it doesn't exist
         string folderpath = AppDomain.CurrentDomain.BaseDirectory + @"Configs\" + folderName;
         if (!Directory.Exists(folderpath))
         {
             Directory.CreateDirectory(folderpath);
             Windows.Main.targetFolder.Items.Add(Path.GetFileName(AppDomain.CurrentDomain.BaseDirectory + @"Configs\" + folderName));
         }
         // Create config file if it doesn't exist
         string     configfile = folderpath + @"\" + folderName + ".json";
         FileStream fs         = null;
         if (!File.Exists(configfile))
         {
             using (fs = File.Create(configfile)) { }
         }
         else
         {
             File.Delete(configfile);
             using (fs = File.Create(configfile)) { }
         }
         if (File.Exists(configfile))
         {
             Windows.ProgressWindow.progressBar.Value = 0;
             Windows.ProgressWindow.Show();
             Windows.ProgressWindow.infoText.Content = "Copying Images";
             for (int i = 0; i < GraphicController.rootList.Count; i++)
             {
                 CopyImages(GraphicController.rootList[i], folderName);
                 Windows.ProgressWindow.progressBar.Value = 100 * i / GraphicController.rootList.Count;
                 UpdateUI();
             }
             Windows.ProgressWindow.infoText.Content = "Creating config file";
             UpdateUI();
             GraphicSerializer serializer = new GraphicSerializer();
             using (StreamWriter sw = new StreamWriter(configfile))
             {
                 using (JsonWriter jw = new JsonTextWriter(sw))
                 {
                     jw.Formatting = Formatting.Indented;
                     serializer.Serialize(GraphicController.rootList, folderName).WriteTo(jw);
                 }
             }
             Windows.ProgressWindow.Hide();
             CustomMessageBox.Show("Config file created.");
         }
     }
     catch (Exception e)
     {
         CustomMessageBox.Show("Failed to create config file. " + e.Message, "Error");
     }
 }