public EditProgWindow(ProgList progList, int id = -1) { InitializeComponent(); this.AcceptButton = this.saveButton; this.CancelButton = this.cancelButton; _progList = progList; if (!JumpListHelper.IsSupported()) { jumpListLabel.Hide(); jumpListLabelState.Hide(); jumpListBox.Hide(); } if (id < 0) { this.Text = Localization.Strings.AddProgram; _prog = _progList.CreateProg(); _isNew = true; } else { this.Text = Localization.Strings.EditProgram; _prog = progList.Get(id); _isNew = false; this.nameField.Text = _prog.Name; this.pathField.Text = _prog.Path; this.argsField.Text = _prog.Args; this.diskImageField.Text = _prog.DiskImage; this.iconField.Text = _prog.Icon; this.jumpListBox.Checked = _prog.InJumpList; updateIconPreview(); } }
public static bool Save(ProgList list) { string filepath = Path.Combine(Directory, Filename); try { if (File.Exists(filepath)) { if (File.Exists(filepath + ".bak")) File.Delete(filepath + ".bak"); File.Move(filepath, filepath + ".bak"); } FileStream file = File.Open(filepath, FileMode.Create); var fm = new BinaryFormatter(); fm.Serialize(file, list); file.Flush(); file.Close(); if (File.Exists(filepath + ".bak")) File.Delete(filepath + ".bak"); return true; } catch (Exception e) { LogHelper.WriteLine(e.Message + Environment.NewLine + e.StackTrace); if (File.Exists(filepath)) File.Delete(filepath); if (File.Exists(filepath + ".bak")) File.Move(filepath + ".bak", filepath); return false; } }
public bool Reload() { ProgList tmp = Load(); if (tmp == null) { return(false); } CurrentID = tmp.CurrentID; _progs = tmp.Progs; return(true); }
public static bool Save(ProgList list) { string filepath = Path.Combine(Directory, Filename); try { if (File.Exists(filepath)) { if (File.Exists(filepath + ".bak")) { File.Delete(filepath + ".bak"); } File.Move(filepath, filepath + ".bak"); } FileStream file = File.Open(filepath, FileMode.Create); var fm = new BinaryFormatter(); fm.Serialize(file, list); file.Flush(); file.Close(); if (File.Exists(filepath + ".bak")) { File.Delete(filepath + ".bak"); } return(true); } catch (Exception e) { LogHelper.WriteLine(e.Message + Environment.NewLine + e.StackTrace); if (File.Exists(filepath)) { File.Delete(filepath); } if (File.Exists(filepath + ".bak")) { File.Move(filepath + ".bak", filepath); } return(false); } }
public static void Update() { if (IsSupported()) { JumpList jumpList = JumpList.CreateJumpList(); List<Prog> progs = new ProgList().GetJumpList(); progs.Reverse(); foreach (Prog prog in progs) { var task = new JumpListLink(System.Reflection.Assembly.GetEntryAssembly().Location, prog.Name) { Arguments = "start " + prog.ID }; if (File.Exists(prog.Icon)) task.IconReference = new IconReference(@prog.Icon, 0); task.WorkingDirectory = Environment.CurrentDirectory; jumpList.AddUserTasks(task); } jumpList.Refresh(); } }
private static int Start(string progName) { var trayIcon = new NotifyIcon {Icon = GUI.Properties.Resources.icon}; var progs = new ProgList(); Prog prog; try { int progId = Int32.Parse(progName); prog = progs.Get(progId); } catch (FormatException) { prog = progs.Get(progName); } if (prog == null || !prog.IsOK() || (prog.DiskImage.Length > 0 && !prog.DiskImageOK())) { ShowError(String.Format(Localization.Strings.ProgNotFound, progName)); return -1; } var info = new InfoWindow(String.Format(Localization.Strings.ProgPreparing, prog.Name)); info.Show(); trayIcon.Text = String.Format(Localization.Strings.ProgWaitingEnd, prog.Name); VirtualDrive virtualDrive = null; if(prog.DiskImage.Length > 0) { if (!new MainWindow().findDT()) { return -1; } var opts = new Options(); if (!opts.Reload()) { ShowError(Localization.Strings.OptionsError); return -1; } virtualDrive = opts.VirtualDrive; if (!virtualDrive.IsValid) { info.Close(); ShowError(Localization.Strings.InvalidDrive + " : " + virtualDrive); return -1; } info.Close(); info = new InfoWindow(String.Format(Localization.Strings.DiskImageMounting, prog.DiskImage, prog.Name)); info.Show(); if (!prog.MountDiskImage(virtualDrive)) { ShowError(Localization.Strings.ErrorMounting); return -1; } } info.Close(); info = new InfoWindow(String.Format(Localization.Strings.ProgStarting, prog.Name)); info.Show(); Process proc = prog.Start(); trayIcon.Visible = true; info.Close(); proc.WaitForExit(); trayIcon.Visible = false; if (virtualDrive != null && virtualDrive.IsValid) { info = new InfoWindow(Localization.Strings.DiskImageUnmounting); info.Show(); virtualDrive.Umount(); info.Close(); } return 0; }