public void saveConfig(ConfigurationSaveItem saveItem, bool overwrite) { try { if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } string completePathString = folderPath + @"\" + saveItem.viewItem.configName + ".config"; if (File.Exists(completePathString) && overwrite == false) { windowRef.createNewDialog.Hide(); _ = new CustomDialog("Error", "A file with the same name already exists.").ShowAsync(); return; } saveItemList.Add(saveItem); File.WriteAllText(completePathString, JsonConvert.SerializeObject(saveItem)); LoggerFactory.debug(this, "New file saved as: " + saveItem.viewItem.configName); } catch (Exception ex) { LoggerFactory.debug(this, "Error writing file - " + ex.Message); } }
public void loadConfigs() { try { if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); _ = new CustomDialog("Information", "Detected a first boot, creating configs directory.").ShowAsync(); } string[] filePaths = System.IO.Directory.GetFiles(folderPath, "*.config"); //I should probably be doing this in a new thread, will change later foreach (string path in filePaths) { ConfigurationSaveItem saveItem = JsonConvert.DeserializeObject <ConfigurationSaveItem>(File.ReadAllText(path)); saveItemList.Add(saveItem); windowRef.configView.Items.Add(saveItem.viewItem); } } catch (Exception ex) { _ = new CustomDialog("Error", "Could not load configurations - " + ex.Message).ShowAsync(); } }