public void UpdateVersionListView()
        {
            jsinit.ClearVersions();
            GetVersions();
            //MessageBox.Show("herre");
            foreach (
                VersionManifest version in
                Directory.GetDirectories(_configuration.McVersions)
                .Select(versionDir => new DirectoryInfo(versionDir))
                .Where(VersionManifest.IsValid)
                .Select(info => VersionManifest.ParseVersion(info, false)))
            {
                jsinit.AddVersions(version.ReleaseType, version.VersionId, true);
                //versionsListView.Items.Add(version.VersionId, version.ReleaseType, version.ReleaseTime, version.LastUpdateTime,
                //  version.AssetsIndex ?? "null", version.InheritsFrom ?? _configuration.Localization.Independent);
            }
            string
                path = Path.Combine(_configuration.McVersions,
                                    _selectedProfile.SelectedVersion ?? GetLatestVersion(_selectedProfile) + @"\");

            string state = _configuration.Localization.ReadyToLaunch;

            // LaunchButton.Enabled = true;
            if (!File.Exists(string.Format(@"{0}\{1}.json", path, _selectedProfile.SelectedVersion ??
                                           GetLatestVersion(_selectedProfile))))
            {
                state = _configuration.Localization.ReadyToDownload;
                if (_configuration.Arguments.OfflineMode)
                {
                    //   LaunchButton.Enabled = false;
                }
                if (jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).Count() >= 1 && jsinit.VersionList.Where(x => x.Instaled == true).Count() >= 1)
                {
                    jsinit.SelectVersion(jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).First().VersionName + "," +
                                         jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).First().VersionData);
                }
                //   SelectedVersion.Text = string.Format(state, _selectedProfile.SelectedVersion ??
                //     GetLatestVersion(_selectedProfile));
                return;
            }
            if (!File.Exists(string.Format(@"{0}\{1}.jar", path, _selectedProfile.SelectedVersion ??
                                           GetLatestVersion(_selectedProfile))) && VersionManifest.ParseVersion(new DirectoryInfo(path)).InheritsFrom == null)
            {
                state = _configuration.Localization.ReadyToDownload;
                if (_configuration.Arguments.OfflineMode)
                {
                    //  LaunchButton.Enabled = false;
                }
            }
            if (jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).Count() >= 1 && jsinit.VersionList.Where(x => x.Instaled == true).Count() >= 1)
            {
                jsinit.SelectVersion(jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).First().VersionName + "," +
                                     jsinit.VersionList.Where(x => x.VersionData == _selectedProfile.SelectedVersion).First().VersionData);
            }
        }
        private void DownloadVersion(string version)
        {
            string path = Path.Combine(_mcVersions, version + @"\");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            AppendLog($"Validating files for Minecraft {version}...");
            SetStatusLabel(FindResource("r_LabelStatusValidatingVersion").ToString());

            if (!File.Exists($@"{path}\{version}.json"))
            {
                RawVersionListManifest versionList =
                    RawVersionListManifest.ParseList(_webClient.DownloadString(@"https://launchermeta.mojang.com/mc/game/version_manifest.json"));
                AppendLog(" Downloading JSON...");
                _webClient.DownloadFile(
                    new Uri(versionList.GetVersion(version)?.ManifestUrl ?? string.Format(
                                "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.json", version)),
                    string.Format(@"{0}\{1}\{1}.json", _mcVersions, version));
            }

            VersionManifest selectedVersionManifest = VersionManifest.ParseVersion(
                new DirectoryInfo(_mcVersions + @"\" + version), false);

            if ((!File.Exists($"{path}/{version}.jar")) && selectedVersionManifest.InheritsFrom == null)
            {
                AppendLog(" Downloading JAR...");
                _webClient.DownloadFile(new Uri(selectedVersionManifest.DownloadInfo?.Client.Url
                                                ?? string.Format(
                                                    "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.jar",
                                                    version)),
                                        string.Format("{0}/{1}/{1}.jar", _mcVersions, version));
            }

            if (selectedVersionManifest.InheritsFrom != null)
            {
                DownloadVersion(selectedVersionManifest.InheritsFrom);
            }
        }
Example #3
0
        private void GetVersions()
        {
            versionsDropDownList.Items.Clear();
            versionsDropDownList.Items.Add(_configuration.Localization.UseLatestVersion);
            List <string> list = new List <string>();
            JObject       json = JObject.Parse(File.ReadAllText(_configuration.McVersions + @"\versions.json"));

            foreach (JObject ver in json["versions"])
            {
                string id         = ver["id"].ToString(),
                             type = ver["type"].ToString(),
                             text = $"{type} {id}";
                list.Add(string.Format("{0} {1}", type, id));
                if (IsVersionInstalled(id))
                {
                    text += " \u2705";
                }
                RadListDataItem ritem = new RadListDataItem
                {
                    Text = text,
                    Tag  = id
                };
                switch (type)
                {
                case "snapshot":
                    if (snapshotsCheckBox.Checked)
                    {
                        versionsDropDownList.Items.Add(ritem);
                    }
                    break;

                case "old_beta":
                    if (betaCheckBox.Checked)
                    {
                        versionsDropDownList.Items.Add(ritem);
                    }
                    break;

                case "old_alpha":
                    if (alphaCheckBox.Checked)
                    {
                        versionsDropDownList.Items.Add(ritem);
                    }
                    break;

                case "release":
                    versionsDropDownList.Items.Add(ritem);
                    break;

                default:
                    if (otherCheckBox.Checked)
                    {
                        versionsDropDownList.Items.Add(ritem);
                    }
                    break;
                }
            }
            if (otherCheckBox.Checked)
            {
                foreach (VersionManifest version in from b in Directory.GetDirectories(_configuration.McVersions)
                         where File.Exists(string.Format(@"{0}\{1}\{1}.json", _configuration.McVersions,
                                                         new DirectoryInfo(b).Name))
                         let add = list.All(a => !a.Contains(new DirectoryInfo(b).Name))
                                   where add
                                   where VersionManifest.IsValid(new DirectoryInfo(string.Format(@"{0}\{1}\", _configuration.McVersions,
                                                                                                 new DirectoryInfo(b).Name)))
                                   select
                                   VersionManifest.ParseVersion(
                             new DirectoryInfo(string.Format(@"{0}\{1}\", _configuration.McVersions,
                                                             new DirectoryInfo(b).Name)), false))
                {
                    versionsDropDownList.Items.Add(new RadListDataItem(version.ReleaseType + " " + version.VersionId)
                    {
                        Tag = version.VersionId
                    });
                }
            }
            versionsDropDownList.Items[0].Text = string.Format(versionsDropDownList.Items[0].Text, versionsDropDownList.Items[1].Tag);
            if (IsVersionInstalled(versionsDropDownList.Items[1].Tag.ToString()))
            {
                versionsDropDownList.Items[0].Text += " \u2705";
            }
            if (Profile.SelectedVersion != null)
            {
                foreach (
                    RadListDataItem a in
                    versionsDropDownList.Items.Where(a => a.Tag?.ToString() == Profile.SelectedVersion))
                {
                    versionsDropDownList.SelectedItem = a;
                    return;
                }
            }
            versionsDropDownList.SelectedIndex = 0;
        }
        private void DownloadLibraries(string version)
        {
            VersionManifest selectedVersionManifest = VersionManifest.ParseVersion(
                new DirectoryInfo(_mcVersions + @"\" + version));
            Dictionary <DownloadEntry, bool> libsToDownload = new Dictionary <DownloadEntry, bool>();

            AppendLog("Validating libraries...");
            SetStatusLabel(FindResource("r_LabelStatusValidatingLibraries").ToString());
            foreach (Lib a in selectedVersionManifest.Libs)
            {
                if (!a.IsForWindows())
                {
                    continue;
                }

                if (a.DownloadInfo == null)
                {
                    libsToDownload.Add(new DownloadEntry {
                        Path = a.GetPath(),
                        Url  = a.GetUrl()
                    }, false);
                    continue;
                }

                foreach (DownloadEntry entry in a.DownloadInfo?.GetDownloadsEntries(dotMCLauncher.OperatingSystem.WINDOWS))
                {
                    if (entry == null)
                    {
                        continue;
                    }

                    entry.Path = entry.Path ?? a.GetPath();
                    entry.Url  = entry.Url ?? a.Url;
                    libsToDownload.Add(entry, entry.IsNative);
                }
            }

            foreach (DownloadEntry entry in libsToDownload.Keys)
            {
                if (File.Exists(_mcLibs + @"\" + entry.Path))
                {
                    continue;
                }
                AppendLog($"Processing {entry.Path}...");
                string directory = Path.GetDirectoryName(_mcLibs + @"\" + entry.Path);
                if (!File.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }

                try {
                    if (entry.Url != null && entry.Url.Contains("minecraftforge"))
                    {
                        AppendLog(" Downloading compressed library...");
                        try {
                            _webClient.DownloadFile(entry.Url + ".pack.xz",
                                                    _mcLibs + @"\" + entry.Path + ".pack.xz");
                            AppendLog(" Decompressing with external process...");
                            Process process = new Process {
                                StartInfo =
                                {
                                    RedirectStandardOutput = true,
                                    UseShellExecute        = false,
                                    CreateNoWindow         = true,
                                    WorkingDirectory       = _tempDir,
                                    FileName  = _javaPath,
                                    Arguments =
                                        "-cp \"xz-1.8.jar;LibraryUnpacker.jar\" ru.dedepete.forgefier.LibraryUnpacker " +
                                        $"\"{_mcLibs + @"\" + entry.Path + ".pack.xz"}\" \"{_mcLibs + @"\" + entry.Path}\""
                                }
                            };
                            process.Start();
                            string output = process.StandardOutput.ReadToEnd();
                            process.WaitForExit();
                            AppendLog($"  Process exited with code {process.ExitCode}.");
                            if (process.ExitCode != 0)
                            {
                                AppendLog($"  Output:\n{output}");
                            }

                            AppendLog(" Removing .PACK.XZ...");
                            File.Delete(_mcLibs + @"\" + entry.Path + ".pack.xz");
                            continue;
                        }
                        catch (Exception exception) {
                            AppendLog($" Failed to download compressed library: {exception.Message}");
                        }
                    }

                    AppendLog(" Downloading library...");
                    _webClient.DownloadFile(entry.Url ?? @"https://libraries.minecraft.net/" + entry.Path,
                                            _mcLibs + @"\" + entry.Path);
                }
                catch (WebException exception) {
                    AppendLog($" Failed to download library: {exception.Message}");
                    AppendLog(" Removing corrupted file...");
                    File.Delete(_mcLibs + @"\" + entry.Path);
                }
            }
        }
        public string DownloadLibraries()
        {
            StringBuilder   libraries = new StringBuilder();
            VersionManifest selectedVersionManifest = VersionManifest.ParseVersion(
                new DirectoryInfo(_configuration.McVersions + @"\" +
                                  (_versionToLaunch ??
                                   (_selectedProfile.SelectedVersion ?? GetLatestVersion(_selectedProfile)))));

            //MessageBox.Show(_versionToLaunch);
            SetStatusBarVisibility(true);
            StatusBarValue = 0;
            jsinit.InstallBarProgress("Проверка библиотек...", 20);
            //UpdateStatusBarText(_configuration.Localization.CheckingLibraries);
            //AppendLog("Preparing required libraries...");
            Dictionary <DownloadEntry, bool> libsToDownload = new Dictionary <DownloadEntry, bool>();

            foreach (Lib a in selectedVersionManifest.Libs)
            {
                if (!a.IsForWindows())
                {
                    continue;
                }
                if (a.DownloadInfo == null)
                {
                    libsToDownload.Add(new DownloadEntry
                    {
                        Path = a.GetPath(),
                        Url  = a.GetUrl()
                    }, false);
                    continue;
                }
                foreach (DownloadEntry entry in a.DownloadInfo?.GetDownloadsEntries(OS.WINDOWS))
                {
                    if (entry == null)
                    {
                        continue;
                    }
                    entry.Path = entry.Path ?? a.GetPath();
                    entry.Url  = entry.Url ?? a.Url;
                    libsToDownload.Add(entry, entry.IsNative);
                }
            }
            SetStatusBarMaxValue(libsToDownload.Count + 1);
            int maxlen = libsToDownload.Keys.Count;
            //MessageBox.Show(maxlen.ToString());
            int step = 0;

            foreach (DownloadEntry entry in libsToDownload.Keys)
            {
                StatusBarValue++;
                if (!File.Exists(_configuration.McLibs + @"\" + entry.Path) ||
                    _restoreVersion)
                {
                    if (!_configuration.Arguments.OfflineMode)
                    {
                        //   UpdateStatusBarAndLog($"Downloading {entry.Path.Replace('/', '\\')}...");
                        string directory = Path.GetDirectoryName(_configuration.McLibs + @"\" + entry.Path);
                        step++;
                        int stepf = Convert.ToInt32(Math.Truncate(step * (20F / (float)maxlen)));
                        jsinit.InstallBarProgress("Загрузка библиотеки " + entry.Url, 20 + stepf);
                        // AppendDebug("Url: " + (entry.Url ?? @"https://libraries.minecraft.net/" + entry.Path));
                        //  AppendDebug("DownloadDir: " + directory);
                        //  AppendDebug("LibPath: " + entry.Path.Replace('/', '\\'));
                        if (!File.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }
                        try
                        {
                            new WebClient().DownloadFile(entry.Url ?? @"https://libraries.minecraft.net/" + entry.Path,
                                                         _configuration.McLibs + @"\" + entry.Path);
                        }
                        catch (WebException ex)
                        {
                            //  AppendException("Downloading failed: " + ex.Message);
                            File.Delete(_configuration.McLibs + @"\" + entry.Path);
                            continue;
                        }
                        catch (Exception ex)
                        {
                            //  AppendException("Downloading failed: " + ex.Message);
                            continue;
                        }
                    }
                    else
                    {
                        // AppendException($"Unable to download {entry.Path}: offline-mode enabled.");
                    }
                }
                if (entry.IsNative)
                {
                    //  UpdateStatusBarAndLog($"Unpacking {entry.Path.Replace('/', '\\')}...");
                    using (ZipFile zip = ZipFile.Read(_configuration.McLibs + @"\" + entry.Path))
                    {
                        foreach (ZipEntry zipEntry in zip.Where(zipEntry => zipEntry.FileName.EndsWith(".dll")))
                        {
                            //AppendDebug($"Unzipping {zipEntry.FileName}");
                            try
                            {
                                zipEntry.Extract(_configuration.McDirectory + @"\natives\",
                                                 ExtractExistingFileAction.OverwriteSilently);
                            }
                            catch (Exception ex)
                            {
                                //AppendException(ex.Message);
                            }
                        }
                    }
                }
                else
                {
                    libraries.Append(_configuration.McLibs + @"\" + entry.Path.Replace('/', '\\') + ";");
                }
                //UpdateStatusBarText(_configuration.Localization.CheckingLibraries);
            }
            libraries.Append(string.Format(@"{0}\{1}\{1}.jar", _configuration.McVersions,
                                           selectedVersionManifest.GetBaseJar()));
            jsinit.InstallBarProgress("Проверка библиотек завершена", 40);
            return(libraries.ToString());
        }
        public void DownloadVersion(string version)
        {
            if (ForgeVersions.versions.Contains(version))
            {
                string forgeversion = version;
                version = version.Split('-')[0];
                string    filename;
                WebClient downloader = new WebClient();
                downloader.DownloadProgressChanged += (_, e) =>
                {
                    StatusBarValue = e.ProgressPercentage;
                };
                SetStatusBarVisibility(true);
                SetStatusBarMaxValue(100);
                StatusBarValue = 0;
                //UpdateStatusBarText(string.Format(_configuration.Localization.CheckingVersionAvailability, version));
                jsinit.InstallBarProgress("Проверка установленной верссии..", 10);
                string path = Path.Combine(_configuration.McVersions, version + @"\");
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (!File.Exists($@"{path}\{version}.json") || _restoreVersion)
                {
                    if (!_configuration.Arguments.OfflineMode)
                    {
                        filename = version + ".json";
                        jsinit.InstallBarProgress("Загрузка верссии..", 10);
                        downloader.DownloadFileTaskAsync(
                            new Uri(_versionList.GetVersion(version)?.ManifestUrl ?? string.Format(
                                        "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.json", version)),
                            string.Format(@"{0}\{1}\{1}.json", _configuration.McVersions, version)).Wait();
                    }
                    else
                    {
                        // AppendException($"Unable to download version {version}: offline-mode enabled.");
                        return;
                    }
                }
                StatusBarValue = 0;
                VersionManifest selectedVersionManifest = VersionManifest.ParseVersion(
                    new DirectoryInfo(_configuration.McVersions + @"\" + version), false);
                if ((!File.Exists($"{path}/{version}.jar") || _restoreVersion) &&
                    selectedVersionManifest.InheritsFrom == null)
                {
                    if (!_configuration.Arguments.OfflineMode)
                    {
                        filename = version + ".jar";
                        // UpdateStatusBarAndLog($"Downloading {filename}...", new StackFrame().GetMethod().Name);
                        downloader.DownloadFileTaskAsync(new Uri(selectedVersionManifest.DownloadInfo?.Client.Url
                                                                 ??
                                                                 string.Format(
                                                                     "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.jar",
                                                                     version)),
                                                         string.Format("{0}/{1}/{1}.jar", _configuration.McVersions, version)).Wait();
                    }
                    else
                    {
                        // AppendException($"Unable to download version {version}: offline-mode enabled.");
                        return;
                    }
                }
                if (selectedVersionManifest.InheritsFrom != null)
                {
                    DownloadVersion(selectedVersionManifest.InheritsFrom);
                }
                jsinit.InstallBarProgress("Установка forge", 10);
                if (!File.Exists(_configuration.McVersions + "/" + forgeversion + "/" + forgeversion + ".json"))
                {
                    McForgeVersion CurForge = new McForgeVersion(forgeversion);
                    //InstallationWindow installationWindow = new InstallationWindow(_configuration.McDirectory, cur, "1.14.4-forge28.0.102-1.14.4", "Forge", Java.JavaInstallationPath);
                    InstallationWindow installation = new InstallationWindow(_configuration.McDirectory, CurForge, forgeversion, "Forge", Java.JavaInstallationPath);
                    installation.Window_Loaded();
                }
            }
            else
            {
                string    filename;
                WebClient downloader = new WebClient();
                downloader.DownloadProgressChanged += (_, e) =>
                {
                    StatusBarValue = e.ProgressPercentage;
                };
                SetStatusBarVisibility(true);
                SetStatusBarMaxValue(100);
                StatusBarValue = 0;
                // UpdateStatusBarText(string.Format(_configuration.Localization.CheckingVersionAvailability, version));
                // AppendLog($"Checking '{version}' version availability...");
                string path = Path.Combine(_configuration.McVersions, version + @"\");

                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                if (!File.Exists($@"{path}\{version}.json") || _restoreVersion)
                {
                    if (!_configuration.Arguments.OfflineMode)
                    {
                        filename = version + ".json";
                        // UpdateStatusBarAndLog($"Downloading {filename}...", new StackFrame().GetMethod().Name);
                        downloader.DownloadFileTaskAsync(
                            new Uri(_versionList.GetVersion(version)?.ManifestUrl ?? string.Format(
                                        "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.json", version)),
                            string.Format(@"{0}\{1}\{1}.json", _configuration.McVersions, version)).Wait();
                    }
                    else
                    {
                        // AppendException($"Unable to download version {version}: offline-mode enabled.");
                        return;
                    }
                }
                StatusBarValue = 0;
                VersionManifest selectedVersionManifest = VersionManifest.ParseVersion(
                    new DirectoryInfo(_configuration.McVersions + @"\" + version), false);
                if ((!File.Exists($"{path}/{version}.jar") || _restoreVersion) &&
                    selectedVersionManifest.InheritsFrom == null)
                {
                    if (!_configuration.Arguments.OfflineMode)
                    {
                        filename = version + ".jar";
                        //UpdateStatusBarAndLog($"Downloading {filename}...", new StackFrame().GetMethod().Name);
                        downloader.DownloadFileTaskAsync(new Uri(selectedVersionManifest.DownloadInfo?.Client.Url
                                                                 ??
                                                                 string.Format(
                                                                     "https://s3.amazonaws.com/Minecraft.Download/versions/{0}/{0}.jar",
                                                                     version)),
                                                         string.Format("{0}/{1}/{1}.jar", _configuration.McVersions, version)).Wait();
                    }
                    else
                    {
                        //  AppendException($"Unable to download version {version}: offline-mode enabled.");
                        return;
                    }
                }
                if (selectedVersionManifest.InheritsFrom != null)
                {
                    DownloadVersion(selectedVersionManifest.InheritsFrom);
                }
                // AppendLog($@"Finished checking {version} version avalability.");
            }
        }
        public void GetVersions()
        {
            jsinit.ClearVersions();

            // versionsDropDownList.Items.Add(_configuration.Localization.UseLatestVersion);
            List <string> list = new List <string>();
            JObject       json = JObject.Parse(File.ReadAllText(_configuration.McVersions + @"\versions.json"));

            foreach (JObject ver in json["versions"])
            {
                string id         = ver["id"].ToString(),
                             type = ver["type"].ToString(),
                             text = $"{type} {id}";
                list.Add(string.Format("{0} {1}", type, id));



                switch (type)
                {
                case "snapshot":
                    if (_configuration.ApplicationConfiguration.SnapEnable == true)
                    {
                        jsinit.AddVersions(text.Split(' ')[0], id, IsVersionInstalled(id));
                    }
                    break;

                case "old_beta":

                    break;

                case "old_alpha":

                    break;

                case "release":
                    jsinit.AddVersions(text.Split(' ')[0], id, IsVersionInstalled(id));
                    break;

                default:

                    jsinit.AddVersions(text, id, IsVersionInstalled(id));

                    break;
                }
            }

            foreach (String version in ForgeVersions.versions)
            {
                jsinit.AddVersions("Forge", version, IsVersionInstalled(version));
            }



            foreach (VersionManifest version in from b in Directory.GetDirectories(_configuration.McVersions)
                     where File.Exists(string.Format(@"{0}\{1}\{1}.json", _configuration.McVersions,
                                                     new DirectoryInfo(b).Name))
                     let add = list.All(a => !a.Contains(new DirectoryInfo(b).Name))
                               where add
                               where VersionManifest.IsValid(new DirectoryInfo(string.Format(@"{0}\{1}\", _configuration.McVersions,
                                                                                             new DirectoryInfo(b).Name)))
                               select
                               VersionManifest.ParseVersion(
                         new DirectoryInfo(string.Format(@"{0}\{1}\", _configuration.McVersions,
                                                         new DirectoryInfo(b).Name)), false))
            {
                jsinit.AddVersions("Модификация", version.VersionId, true);
            }

            if (jsinit.AlreadyInstalled)
            {
                jsinit.updateVersions();
            }
        }
        public void DownloadAssets()
        {
            // UpdateStatusBarAndLog("Checking game assets...");
            jsinit.InstallBarProgress("Проверка ресурсов...", 40);
            VersionManifest selectedVersionManifest = VersionManifest.ParseVersion(
                new DirectoryInfo(_configuration.McVersions + @"\" +
                                  (_versionToLaunch ??
                                   (_selectedProfile.SelectedVersion ?? GetLatestVersion(_selectedProfile)))));

            if (selectedVersionManifest.InheritsFrom != null)
            {
                selectedVersionManifest = selectedVersionManifest.InheritableVersionManifest;
            }
            string file = string.Format(@"{0}\assets\indexes\{1}.json", _configuration.McDirectory,
                                        selectedVersionManifest.AssetsIndex ?? "legacy");

            if (!File.Exists(file))
            {
                if (!Directory.Exists(Path.GetDirectoryName(file)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(file));
                }
                new WebClient().DownloadFile(selectedVersionManifest.GetAssetIndexDownloadUrl(), file);
            }
            AssetsManifest manifest = AssetsManifest.Parse(file);

            StatusBarValue = 0;
            SetStatusBarMaxValue(manifest.Objects.Select(pair => pair.Value.Hash.GetFullPath()).Count(filename => !File.Exists(_configuration.McDirectory + @"\assets\objects\" +
                                                                                                                               filename) || _restoreVersion) + 1);
            int maxlen = manifest.Objects.Select(pair => pair.Value).Where(asset => !File.Exists(_configuration.McDirectory + @"\assets\objects\" +
                                                                                                 asset.Hash.GetFullPath())).Count();
            //MessageBox.Show(maxlen.ToString());
            int step = 0;

            foreach (Asset asset in manifest.Objects.Select(pair => pair.Value).Where(asset => !File.Exists(_configuration.McDirectory + @"\assets\objects\" +
                                                                                                            asset.Hash.GetFullPath()) || _restoreVersion))
            {
                string directory = _configuration.McDirectory + @"\assets\objects\" + asset.Hash.GetDirectoryName();
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
                try
                {
                    // AppendDebug($"Downloading {asset.Hash}...");
                    step++;
                    int stepf = Convert.ToInt32(Math.Truncate(step * (50F / (float)maxlen)));
                    jsinit.InstallBarProgress("Загрузка ресурса " + asset.AssociatedName, 40 + stepf);
                    new WebClient().DownloadFile(@"http://resources.download.minecraft.net/" + asset.Hash.GetFullPath(),
                                                 _configuration.McDirectory + @"\assets\objects\" + asset.Hash.GetFullPath());
                }
                catch (Exception ex)
                {
                    //  AppendException(ex.ToString());
                }
                StatusBarValue++;
            }
            jsinit.InstallBarProgress("Проверка ресурсов завершена", 90);
            if (selectedVersionManifest.AssetsIndex == null || selectedVersionManifest.AssetsIndex == "legacy")
            {
                StatusBarValue = 0;
                SetStatusBarMaxValue(manifest.Objects.Select(pair => pair.Value.AssociatedName)
                                     .Count(
                                         filename =>
                                         !File.Exists(_configuration.McDirectory + @"\assets\virtual\legacy\" +
                                                      filename) || _restoreVersion) + 1);
                jsinit.InstallBarProgress("Конвертация ресурсов...", 90);
                foreach (Asset asset in manifest.Objects.Select(pair => pair.Value)
                         .Where(asset =>
                                !File.Exists(_configuration.McDirectory + @"\assets\virtual\legacy\" +
                                             asset.AssociatedName) || _restoreVersion))
                {
                    string filename = _configuration.McDirectory + @"\assets\virtual\legacy\" + asset.AssociatedName;
                    try
                    {
                        if (!Directory.Exists(new FileInfo(filename).DirectoryName))
                        {
                            Directory.CreateDirectory(new FileInfo(filename).DirectoryName);
                        }

                        File.Copy(_configuration.McDirectory + @"\assets\objects\" + asset.Hash.GetFullPath(),
                                  filename);
                    }
                    catch (Exception ex)
                    {
                        //  AppendLog(ex.ToString());
                    }
                    StatusBarValue++;
                }
                jsinit.InstallBarProgress("Конвертация ресурсов завершена", 60);
            }
            SetStatusBarVisibility(false);
        }