예제 #1
0
        private IMachine OpenMachine()
        {
            PromptForFileEventArgs args = new PromptForFileEventArgs(FileTypes.Machine, true);

            //args.FileType = FileTypes.Machine;
            //args.Existing = true;
            PromptForFile?.Invoke(this, args);

            string filepath = args.Filepath;

            if (filepath == null)
            {
                return(null);
            }

            string   fullFilepath = System.IO.Path.GetFullPath(filepath);
            IMachine machine      = Machines.FirstOrDefault(
                m =>
            {
                if (m is IPersistableMachine pm)
                {
                    return(String.Compare(pm.PersistantFilepath, fullFilepath, true) == 0);
                }

                return(false);
            });

            if (machine == null)
            {
                machine = _model.AddMachine(fullFilepath, _fileSystem, true);
            }

            return(machine);
        }
예제 #2
0
        public void Persist(IPersistableMachine machine)
        {
            if (machine == null)
            {
                throw new ArgumentNullException(nameof(machine));
            }

            if (!String.IsNullOrEmpty(machine.PersistantFilepath))
            {
                // Should throw exception here?
                return;
            }

            PromptForFileEventArgs args = new PromptForFileEventArgs(FileTypes.Machine, false);

            PromptForFile?.Invoke(this, args);

            string filepath = args.Filepath;

            machine.Persist(_fileSystem, filepath);
        }
예제 #3
0
        private byte[] PromptForMedia(bool disc)
        {
            string    expectedExt = disc ? ".dsk" : ".cdt";
            FileTypes type        = disc ? FileTypes.Disc : FileTypes.Tape;

            PromptForFileEventArgs promptForFileArgs = new PromptForFileEventArgs(type, true);

            PromptForFile?.Invoke(this, promptForFileArgs);

            string filename = promptForFileArgs.Filepath;

            if (filename == null)
            {
                // Action was cancelled by the user.
                return(null);
            }

            byte[] buffer = null;
            string ext    = System.IO.Path.GetExtension(filename);

            if (ext.ToLower() == ".zip")
            {
                string        entry      = null;
                List <string> entries    = _fileSystem.GetZipFileEntryNames(filename);
                List <string> extEntries = entries.Where(x => System.IO.Path.GetExtension(x).ToLower() == expectedExt).ToList();
                if (extEntries.Count == 0)
                {
                    // No images available.
                    Diagnostics.Trace("No files with the extension \"{0}\" found in zip archive \"{1}\".", expectedExt, filename);

                    return(null);
                }
                else if (extEntries.Count == 1)
                {
                    // Don't bother prompting the user, since there's only one!
                    entry = extEntries[0];
                }
                else
                {
                    SelectItemEventArgs selectItemArgs = new SelectItemEventArgs(extEntries);
                    SelectItem?.Invoke(this, selectItemArgs);

                    entry = selectItemArgs.SelectedItem;
                    if (entry == null)
                    {
                        // Action was cancelled by the user.
                        return(null);
                    }
                }

                Diagnostics.Trace("Loading \"{0}\" from zip archive \"{1}\"", entry, filename);
                buffer = _fileSystem.GetZipFileEntry(filename, entry);
            }
            else
            {
                Diagnostics.Trace("Loading \"{0}\"", filename);
                buffer = _fileSystem.ReadBytes(filename);
            }

            return(buffer);
        }