void onDeleteFile(object sender, EventArgs e) { MenuItem item = sender as MenuItem; ContextMenu menu = item.CommandParameter as ContextMenu; FileBaseItem target = (menu.PlacementTarget as StackPanel).Tag as FileBaseItem; if (Debugger.Dlg.ConfirmDlg.Show(string.Format("Delete {1} '{0}'?", target.Name, (target is Folder) ? "folder" : "file")) == true) { try { if (target.Parent is Folder) { ((Folder)target.Parent).Children.Remove(target); } FileOperationAPIWrapper.MoveToRecycleBin(target.Path); } catch (Exception ex) { ErrorHandler.inst().Error(ex); } } }
/// <summary> /// Handle deleting a difficulty that was previously saved /// </summary> /// <param name="row">UI row that was clicked on</param> /// <param name="r">Confirmation from the user</param> private void HandleDeleteDifficulty(DifficultyRow row, int r) { if (r == 1) // User canceled out { row.Toggle.isOn = true; return; } var diff = diffs[row.Name].DifficultyBeatmap; string fileToDelete = Song.GetMapFromDifficultyBeatmap(diff)?.directoryAndFile; if (File.Exists(fileToDelete)) { FileOperationAPIWrapper.MoveToRecycleBin(fileToDelete); } // Remove status effects if present if (copySource != null && row == copySource.Obj && currentCharacteristic == copySource.Characteristic) { CancelCopy(); } if (row == selected) { DeselectDiff(); } currentCharacteristic.difficultyBeatmaps.Remove(diffs[row.Name].DifficultyBeatmap); if (currentCharacteristic.difficultyBeatmaps.Count == 0) { Song.difficultyBeatmapSets.Remove(currentCharacteristic); } diffs.Remove(row.Name); Song.SaveSong(); row.SetInteractable(false); row.NameInput.text = ""; row.ShowDirtyObjects(false, false); characteristicSelect.Recalculate(); }
public static void Main(string[] args) { if (args.Length != 5) { Console.WriteLine("This program should be launched by PoeHUD_PluginsUpdater. Exiting..."); Console.ReadLine(); return; } var poehudUpdateDir = args[0]; var poehudDir = args[1]; var poeHudProcessId = int.Parse(args[2]); var exeToStart = args[3]; var exeToDelete = args[4]; Process poeProcess; try { poeProcess = Process.GetProcessById(poeHudProcessId); poeProcess.Kill(); do { Thread.Sleep(200); }while (!poeProcess.HasExited); Console.WriteLine("PoeHUD closed..."); } catch { Console.WriteLine("PoeHUD process not found..."); } if (exeToDelete != "-" && File.Exists(exeToDelete)) { Console.WriteLine("Deleting old PoeHUD.exe: " + exeToDelete); File.Delete(exeToDelete); } DirectoryInfo updateDirInfo = new DirectoryInfo(poehudUpdateDir); if (!updateDirInfo.Exists) { return; } var backupDir = Path.Combine(updateDirInfo.FullName, UpdateBackupDir); if (Directory.Exists(backupDir)) { FileOperationAPIWrapper.MoveToRecycleBin(backupDir); } if (MoveDirectoryFiles(poehudDir, updateDirInfo.FullName, poehudDir)) { Console.WriteLine("Deleting temp dir:\t" + updateDirInfo.FullName); Directory.Delete(updateDirInfo.FullName, true); } else { Console.WriteLine("PoeHUD Updater: some files wasn't moved or replaced while update. You can move them manually: " + updateDirInfo.FullName, 20); } Console.WriteLine(); Console.WriteLine("Update completed!"); Console.WriteLine(); Console.WriteLine("Starting poehud: " + exeToStart); var processInfo = new ProcessStartInfo("cmd.exe", "/c " + exeToStart); processInfo.CreateNoWindow = true; processInfo.UseShellExecute = false; // *** Redirect the output *** //processInfo.RedirectStandardError = true; //processInfo.RedirectStandardOutput = true; processInfo.WorkingDirectory = poehudDir; processInfo.Verb = "runas"; //this is what actually runs the command as administrator try { var process = Process.Start(processInfo); process.WaitForExit(); process.Close(); } catch (Exception) { Console.WriteLine($"PoeHUD Updater: Can't start {exeToStart} with admin rights", 10); //If you are here the user clicked declined to grant admin privileges (or he's not administrator) } Console.WriteLine("PoeHUD launched! Press any key to close this window"); //Console.ReadLine(); }
public bool DeleteSong(Song song) { bool zippedSong = false; string path = ""; CustomLevel level = SongLoader.CustomLevels.FirstOrDefault(x => x.levelID.StartsWith(song.hash)); if (string.IsNullOrEmpty(song.path)) { if (level != null) { path = level.customSongInfo.path; } } else { path = song.path; } if (string.IsNullOrEmpty(path)) { return(false); } if (!Directory.Exists(path)) { return(false); } if (path.Contains("/.cache/")) { zippedSong = true; } if (zippedSong) { Logger.Log("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } string songHash = Directory.GetParent(path).Name; try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Log("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Can't find or delete empty folder!"); } string docPath = Application.dataPath; docPath = docPath.Substring(0, docPath.Length - 5); docPath = docPath.Substring(0, docPath.LastIndexOf("/")); string customSongsPath = docPath + "/CustomSongs/"; string hash = ""; foreach (string file in Directory.GetFiles(customSongsPath, "*.zip")) { if (CreateMD5FromFile(file, out hash)) { if (hash == songHash) { File.Delete(file); break; } } } } else { Logger.Log("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Log("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Unable to delete empty folder!"); } } if (level != null) { SongLoader.Instance.RemoveSongWithLevelID(level.levelID); } Logger.Log($"{_alreadyDownloadedSongs.RemoveAll(x => x.Compare(song))} song removed"); return(true); }
void Method() { // only exists on windows FileOperationAPIWrapper.MoveToRecycleBin(""); }
public void DeleteSong(Song song) { bool zippedSong = false; string path = ""; // Console.WriteLine("Deleting: " + song.path); SongCore.Loader.Instance.DeleteSong(song.path, false); /* * CustomLevel level = SongLoader.CustomLevels.FirstOrDefault(x => x.levelID.StartsWith(song.hash)); * * if (level != null) * SongLoader.Instance.RemoveSongWithLevelID(level.levelID); * * if (string.IsNullOrEmpty(song.path)) * { * if (level != null) * path = level.customSongInfo.path; * } * else * { * path = song.path; * } */ path = song.path.Replace('\\', '/'); if (string.IsNullOrEmpty(path)) { return; } if (!Directory.Exists(path)) { return; } if (path.Contains("/.cache/")) { zippedSong = true; } Task.Run(() => { if (zippedSong) { Logger.Info("Deleting \"" + path.Substring(path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } string songHash = Directory.GetParent(path).Name; try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Info("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Can't find or delete empty folder!"); } string docPath = Application.dataPath; docPath = docPath.Substring(0, docPath.Length - 5); docPath = docPath.Substring(0, docPath.LastIndexOf("/")); string customSongsPath = docPath + "/CustomSongs/"; string hash = ""; foreach (string file in Directory.GetFiles(customSongsPath, "*.zip")) { if (CreateMD5FromFile(file, out hash)) { if (hash == songHash) { File.Delete(file); break; } } } } else { try { Logger.Info("Deleting \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); if (PluginConfig.deleteToRecycleBin) { FileOperationAPIWrapper.MoveToRecycleBin(path); } else { Directory.Delete(path, true); } try { if (Directory.GetFileSystemEntries(path.Substring(0, path.LastIndexOf('/'))).Length == 0) { Logger.Info("Deleting empty folder \"" + path.Substring(0, path.LastIndexOf('/')) + "\"..."); Directory.Delete(path.Substring(0, path.LastIndexOf('/')), false); } } catch { Logger.Warning("Unable to delete empty folder!"); } } catch (Exception ex) { Logger.Error("Error Deleting Song:" + song.path); Logger.Error(ex.ToString()); } } Logger.Info($"{_alreadyDownloadedSongs.RemoveAll(x => x.Compare(song))} song removed"); }).ConfigureAwait(false); }