コード例 #1
0
 public Profile(string name, MinecraftVersion version, DateTime lastUsed = default, DateTime created = default, ProfileType type = ProfileType.Custom, List <Mod> modsList = default)
 {
     Name     = string.IsNullOrEmpty(name) ? "<unnamed profile>" : name;
     Version  = version;
     LastUsed = lastUsed;
     Created  = created;
     Type     = type;
     modsList?.ForEach(m => AddMod(m));
 }
コード例 #2
0
        private async Task <bool> Download(Profile p)
        {
            MinecraftVersion        v            = p.Version;
            CancellationTokenSource cancelSource = new CancellationTokenSource();

            LaunchInfo.CancelCommand = new RelayCommand((o) => cancelSource.Cancel());

            Trace.WriteLine("Download start");
            string            dlPath     = Path.Combine(VersionManager.instance.VersionsDirectory, "Minecraft-" + v.Name + ".Appx");
            VersionDownloader downloader = v.Beta ? VersionDownloader.user : VersionDownloader.standard;

            try
            {
                Trace.WriteLine("Initializing Download");
                await downloader.Download(v.UUID, "1", dlPath, (current, total) =>
                {
                    if (LaunchInfo.Status == LaunchStatus.InitializingDownload)
                    {
                        Trace.WriteLine("Actual download started");
                        LaunchInfo.Status = LaunchStatus.Downloading;
                        if (total.HasValue)
                        {
                            LaunchInfo.DownloadSize = total.Value;
                        }
                    }
                    LaunchInfo.DownloadedBytes += current;
                }, cancelSource.Token);

                Trace.WriteLine("Download complete");
            }
            catch (Exception e)
            {
                Trace.WriteLine("Download failed:\n" + e.ToString());
                if (!(e is TaskCanceledException))
                {
                    Utils.ShowErrorDialog("Download failed", string.Format("An error occured while downloading Minecraft {0}.{1}", v.Name, v.Beta ? " Ensure the selected account is the one registered for beta versions in the Xbox Insider app." : ""));
                }
                return(false);
            }
            try
            {
                string dirPath = v.GameDirectory;
                if (Directory.Exists(dirPath))
                {
                    Directory.Delete(dirPath, true);
                }
                Progress <ZipProgress> progress = new Progress <ZipProgress>();
                progress.ProgressChanged += (sender, zipProgress) =>
                {
                    if (LaunchInfo.Status != LaunchStatus.Extracting)
                    {
                        Trace.WriteLine("Extraction started");
                        LaunchInfo.Status   = LaunchStatus.Extracting;
                        LaunchInfo.ZipTotal = zipProgress.Total;
                    }
                    LaunchInfo.ZipProcessed   = zipProgress.Processed;
                    LaunchInfo.ZipCurrentItem = zipProgress.CurrentItem;
                };
                using (ZipArchive zipFile = new ZipArchive(new FileStream(dlPath, FileMode.Open)))
                {
                    zipFile.ExtractToDirectory(dirPath, progress);
                }
                File.Delete(Path.Combine(dirPath, "AppxSignature.p7x"));
                File.Delete(dlPath);
            }
            catch (Exception e)
            {
                Trace.WriteLine("Extraction failed:\n" + e.ToString());
                Utils.ShowErrorDialog("Extraction failed", string.Format("An error occured during extraction to directory:\n{0}", v.GameDirectory));
                return(false);
            }
            v.UpdateInstallStatus();
            return(true);
        }
コード例 #3
0
ファイル: Mod.cs プロジェクト: MinecraftZenova/ZenovaLauncher
 public bool SupportsVersion(MinecraftVersion version)
 {
     return(MCVersionList.Contains(version));
 }