示例#1
0
        /// <exception cref="ArgumentNullException"><paramref name="filePath"/> or <paramref name="spec"/> is <see langword="null" />.</exception>
        /// <exception cref="ArgumentOutOfRangeException">spec</exception>
        public GameArchive(string filePath, GameArchiveSpec spec)
        {
            FilePath = filePath;
            if (filePath == null)
            {
                throw new ArgumentNullException("readStream");
            }
            if (spec == null)
            {
                throw new ArgumentNullException("spec");
            }

            Spec = spec;

            switch (spec.OperatingSystem)
            {
            case OperatingSystem.Windows:
                _impl = new GameZipArchiveReader();
                break;

            case OperatingSystem.Mac:
                _impl = new GameDmgArchiveReader();
                break;

            case OperatingSystem.Linux:
                _impl = new GameTgzArchiveReader();
                break;

            default:
                throw new ArgumentOutOfRangeException("spec");
            }
        }
        public async Task InstallArchiveImpl()
        {
            /*
             * var archiveExtension = GameArchiveSpec.GetArchiveExtension(os);
             *
             * var zipDialog = new OpenFileDialog
             * {
             *  AutoUpgradeEnabled = true,
             *  CheckFileExists = true,
             *  DefaultExt = archiveExtension,
             *  SupportMultiDottedExtensions = true,
             *  Filter = string.Format("Archive Files (*{0}) | *{0}", archiveExtension)
             * };
             *
             * if (zipDialog.ShowDialog() != DialogResult.OK)
             *  return;
             */
            // Do this: http://stackoverflow.com/a/25630554
            // Pass FileName or stream or something as an argument to the second command using Observable.Invoke
            if (InstallFileArchiveFilePath == null)
            {
                return;
            }

            var os          = OperatingSystemEx.CurrentOS;
            var archiveSpec = new GameArchiveSpec(Model.Spec, os);

            try
            {
                var archive = new GameArchive(InstallFileArchiveFilePath, archiveSpec);
                await Model.InstallFromArchive(archive);
            }
            catch (UnauthorizedAccessException)
            {
                MessageBox.Show("Unauthorized access");
            }
            catch (DirectoryNotFoundException)
            {
                MessageBox.Show("The specified path is invalid (for example, it is on an unmapped drive).");
            }
            catch (IOException)
            {
                MessageBox.Show("The directory is a file.-or-The network name is not known.");
            }
            catch (SecurityException)
            {
                MessageBox.Show("Security exception");
            }
        }
        private string OpenArchiveDialogImpl(InstallationSpec spec)
        {
            var os               = OperatingSystemEx.CurrentOS;
            var archiveSpec      = new GameArchiveSpec(spec, os);
            var archiveExtension = GameArchiveSpec.GetArchiveExtension(os);

            var zipDialog = new OpenFileDialog
            {
                AutoUpgradeEnabled           = true,
                CheckFileExists              = true,
                DefaultExt                   = archiveExtension,
                SupportMultiDottedExtensions = true,
                Filter = string.Format("Archive Files (*{0}) | *{0}", archiveExtension)
            };

            if (zipDialog.ShowDialog() != DialogResult.OK)
            {
                return(null);
            }

            return(zipDialog.FileName);
        }