상속: IGlobalModData
예제 #1
0
        public InstallFromDiscLogic(Widget widget, ModContent content, Dictionary<string, ModContent.ModSource> sources, Action afterInstall)
        {
            this.content = content;
            this.sources = sources;

            Log.AddChannel("install", "install.log");

            // this.afterInstall = afterInstall;
            panel = widget.Get("DISC_INSTALL_PANEL");

            titleLabel = panel.Get<LabelWidget>("TITLE");

            primaryButton = panel.Get<ButtonWidget>("PRIMARY_BUTTON");
            secondaryButton = panel.Get<ButtonWidget>("SECONDARY_BUTTON");

            // Progress view
            progressContainer = panel.Get("PROGRESS");
            progressContainer.IsVisible = () => visible == Mode.Progress;
            progressBar = panel.Get<ProgressBarWidget>("PROGRESS_BAR");
            progressLabel = panel.Get<LabelWidget>("PROGRESS_MESSAGE");
            progressLabel.IsVisible = () => visible == Mode.Progress;

            // Message view
            messageContainer = panel.Get("MESSAGE");
            messageContainer.IsVisible = () => visible == Mode.Message;
            messageLabel = messageContainer.Get<LabelWidget>("MESSAGE_MESSAGE");

            // List view
            listContainer = panel.Get("LIST");
            listContainer.IsVisible = () => visible == Mode.List;

            listPanel = listContainer.Get<ScrollPanelWidget>("LIST_PANEL");
            listHeaderTemplate = listPanel.Get("LIST_HEADER_TEMPLATE");
            listTemplate = listPanel.Get<LabelWidget>("LIST_TEMPLATE");
            listPanel.RemoveChildren();

            listLabel = listContainer.Get<LabelWidget>("LIST_MESSAGE");

            DetectContentDisks();
        }
예제 #2
0
        void InstallFromDisc(string path, ModContent.ModSource modSource)
        {
            var message = "";
            ShowProgressbar("Installing Content", () => message);
            ShowDisabledCancel();

            new Task(() =>
            {
                var extracted = new List<string>();

                try
                {
                    foreach (var i in modSource.Install)
                    {
                        switch (i.Key)
                        {
                            case "copy":
                            {
                                var sourceDir = Path.Combine(path, i.Value.Value);
                                foreach (var node in i.Value.Nodes)
                                {
                                    var sourcePath = Path.Combine(sourceDir, node.Value.Value);
                                    var targetPath = Platform.ResolvePath(node.Key);
                                    if (File.Exists(targetPath))
                                    {
                                        Log.Write("install", "Ignoring installed file " + targetPath);
                                        continue;
                                    }

                                    Log.Write("install", "Copying {0} -> {1}".F(sourcePath, targetPath));
                                    extracted.Add(targetPath);
                                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));

                                    using (var source = File.OpenRead(sourcePath))
                                    using (var target = File.OpenWrite(targetPath))
                                    {
                                        var displayFilename = Path.GetFileName(targetPath);
                                        var length = source.Length;

                                        Action<long> onProgress = null;
                                        if (length < ShowPercentageThreshold)
                                            message = "Copying " + displayFilename;
                                        else
                                            onProgress = b => message = "Copying " + displayFilename + " ({0}%)".F(100 * b / length);

                                        CopyStream(source, target, length, onProgress);
                                    }
                                }

                                break;
                            }

                            case "extract-raw":
                            {
                                ExtractFromPackage(ExtractionType.Raw, path, i.Value, extracted, m => message = m);
                                break;
                            }

                            case "extract-blast":
                            {
                                ExtractFromPackage(ExtractionType.Blast, path, i.Value, extracted, m => message = m);
                                break;
                            }

                            case "extract-mscab":
                            {
                                ExtractFromMSCab(path, i.Value, extracted, m => message = m);
                                break;
                            }

                            case "extract-iscab":
                            {
                                ExtractFromISCab(path, i.Value, extracted, m => message = m);
                                break;
                            }

                            case "delete":
                            {
                                var sourcePath = Path.Combine(path, i.Value.Value);

                                // Try as an absolute path
                                if (!File.Exists(sourcePath))
                                    sourcePath = Platform.ResolvePath(i.Value.Value);

                                Log.Write("debug", "Deleting {0}", sourcePath);
                                File.Delete(sourcePath);
                                break;
                            }

                            default:
                                Log.Write("debug", "Unknown installation command {0} - ignoring", i.Key);
                                break;
                        }
                    }

                    Game.RunAfterTick(Ui.CloseWindow);
                }
                catch (Exception e)
                {
                    Log.Write("install", e.ToString());

                    foreach (var f in extracted)
                    {
                        Log.Write("install", "Deleting " + f);
                        File.Delete(f);
                    }

                    Game.RunAfterTick(() =>
                    {
                        ShowMessage("Installation Failed", "Refer to install.log in the logs directory for details.");
                        ShowBackRetry(() => InstallFromDisc(path, modSource));
                    });
                }
            }).Start();
        }
예제 #3
0
        bool IsValidSourcePath(string path, ModContent.ModSource source)
        {
            try
            {
                foreach (var kv in source.IDFiles)
                {
                    var filePath = Path.Combine(path, kv.Key);
                    if (!File.Exists(filePath))
                        return false;

                    using (var fileStream = File.OpenRead(filePath))
                        if (CryptoUtil.SHA1Hash(fileStream) != kv.Value)
                            return false;
                }
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
예제 #4
0
        string FindSourcePath(ModContent.ModSource source, IEnumerable<string> volumes)
        {
            if (source.Type == ModContent.SourceType.Install)
            {
                if (source.RegistryKey == null)
                    return null;

                if (Platform.CurrentPlatform != PlatformType.Windows)
                    return null;

                var path = Microsoft.Win32.Registry.GetValue(source.RegistryKey, source.RegistryValue, null) as string;
                if (path == null)
                    return null;

                return IsValidSourcePath(path, source) ? path : null;
            }

            if (source.Type == ModContent.SourceType.Disc)
                foreach (var volume in volumes)
                    if (IsValidSourcePath(volume, source))
                        return volume;

            return null;
        }