Exemple #1
0
        public static bool Save(Options options)
        {
            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 bf = new BinaryFormatter();
                bf.Serialize(file, options);
                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;
            }
        }
Exemple #2
0
        public OptionsWindow(Options options)
        {
            InitializeComponent();
            _options = options;

            if (!loadDrives())
            {
                LogHelper.RaiseError(this, Localization.Strings.VirtualDriveNoneFound);
            }
        }
Exemple #3
0
        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;
        }