Пример #1
0
 public void RefreshDevices()
 {
     try
     {
         string json = String.Empty;
         using (StreamReader sr = new StreamReader(CombinePaths(appDocs, "PairedDevices.json")))
         {
             string line = "";
             while ((line = sr.ReadLine()) != null)
             {
                 json += line;
             }
         }
         devices = PairedDevices.FromJson(json);
     }
     catch (Exception e)
     {
         if (File.Exists(CombinePaths(appDocs, "PairedDevices.json")))
         {
             File.Delete(CombinePaths(appDocs, "PairedDevices.json"));
         }
         File.WriteAllText(CombinePaths(appDocs, "PairedDevices.json"), devices.ToJson());
     }
 }
Пример #2
0
        public MainFormModel()
        {
            devices           = new PairedDevices();
            templates         = new List <Template>();
            openedTemplate    = 0;
            appDocs           = CombinePaths(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "\\AirPodsUI");
            TemplateLocations = new List <string>();

            #region Directory Creation
            if (!Directory.Exists(appDocs))
            {
                Directory.CreateDirectory(appDocs);
            }

            if (!Directory.Exists(CombinePaths(appDocs, "Logs")))
            {
                Directory.CreateDirectory(CombinePaths(appDocs, "Logs"));
            }

            if (!Directory.Exists(CombinePaths(appDocs, "Assets")))
            {
                Directory.CreateDirectory(CombinePaths(appDocs, "Assets"));
            }

            if (!Directory.Exists(CombinePaths(appDocs, "Templates")))
            {
                Directory.CreateDirectory(CombinePaths(appDocs, "Templates"));
            }
            #endregion

            foreach (var i in Directory.GetFiles(CombinePaths(appDocs, "Templates")))
            {
                if (Path.GetExtension(i.ToLower()) == ".json")
                {
                    try { templates.Add(Template.FromJson(File.ReadAllText(i))); TemplateLocations.Add(i); }
                    catch (Exception e) { continue; }
                }
            }

            try
            {
                string json = String.Empty;
                using (StreamReader sr = new StreamReader(CombinePaths(appDocs, "PairedDevices.json")))
                {
                    string line = "";
                    while ((line = sr.ReadLine()) != null)
                    {
                        json += line;
                    }
                }
                devices = PairedDevices.FromJson(json);
            }
            catch (Exception e)
            {
                if (File.Exists(CombinePaths(appDocs, "PairedDevices.json")))
                {
                    File.Delete(CombinePaths(appDocs, "PairedDevices.json"));
                }
                File.WriteAllText(CombinePaths(appDocs, "PairedDevices.json"), devices.ToJson());
            }
        }