예제 #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
 public bool SupportsVersion(MinecraftVersion version)
 {
     return(MCVersionList.Contains(version));
 }