public async Task <Process> Update() { // Backup the data folder string dataPath = ServerPath.GetServersServerFiles(_serverData.ServerID, "data"); string tempPath = ServerPath.GetServers(_serverData.ServerID, "__temp"); bool needBackup = Directory.Exists(dataPath); if (needBackup) { if (Directory.Exists(tempPath)) { if (!await DirectoryManagement.DeleteAsync(tempPath, true)) { Error = "Fail to delete the temp folder"; return(null); } } if (!await Task.Run(() => { try { Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(dataPath, tempPath); return(true); } catch (Exception e) { Error = e.Message; return(false); } })) { return(null); } } // Delete the serverfiles folder if (!await DirectoryManagement.DeleteAsync(ServerPath.GetServersServerFiles(_serverData.ServerID), true)) { Error = "Fail to delete the serverfiles"; return(null); } // Recreate the serverfiles folder Directory.CreateDirectory(ServerPath.GetServersServerFiles(_serverData.ServerID)); if (needBackup) { // Restore the data folder if (!await Task.Run(() => { try { Microsoft.VisualBasic.FileIO.FileSystem.CopyDirectory(tempPath, dataPath); return(true); } catch (Exception e) { Error = e.Message; return(false); } })) { return(null); } await DirectoryManagement.DeleteAsync(tempPath, true); } // Update the server by install again await Install(); // Return is valid if (IsInstallValid()) { return(null); } Error = "Update fail"; return(null); }