public static async Task <bool> CheckCreateFile(string fileName, string folderName = null) { bool didntExist = false; if (folderName != null) { if (!Directory.Exists(folderName)) { Directory.CreateDirectory(folderName); didntExist = true; } } if (fileName != null) { if (!File.Exists(ConfigControl.appFolder + fileName)) { if (ConfigControl.appFolder + fileName == ConfigControl.appFolder + ConfigControl.config) { ConfigControl.CreateConfig(ConfigControl.appFolder + fileName); } else { var newFile = File.Create(ConfigControl.appFolder + fileName); newFile.Close(); } didntExist = true; } } return(didntExist); }
public static void CopySingleFile(string destination, string sourceFile, bool copyingDirectory = false) { string curFile = string.Empty; string newLocation = string.Empty; try { string name = sourceFile.Substring(sourceFile.LastIndexOf("\\") + 1); curFile = sourceFile; newLocation = destination + name; destination.Replace("//", "/"); destination.Replace("\\\\", "\\"); if (copyingDirectory) { if (!destination.EndsWith(@"\")) { destination += @"\"; } string tempFile = destination + @"CopiedFile"; if (!File.Exists(newLocation)) { if (name == ConfigControl.config) { ConfigControl.portableMode.UpdateValue("true"); ConfigControl.CreateConfig(destination + @"\" + ConfigControl.config); ConfigControl.portableMode.UpdateValue("false"); } else { File.Copy(sourceFile, tempFile, true); File.Move(tempFile, destination + @"\" + name); //renames file } } } else { File.Copy(sourceFile, PathNoOverwrite(destination), true); } } catch (Exception e) { ShowPopup("Couldn't copy individual file to new directory!\nShow more info?", "Copy failed!", "File: " + curFile + "\nfailed to copy to:\n" + newLocation + "\n\nError: " + e.ToString()); } }
private async Task ApplyAll() { ConfigControl.CreateConfig(ConfigControl.appFolder + ConfigControl.config); }