public DownloadList(DownloadMeta meta, System.Collections.Generic.IEnumerable <System.Collections.Generic.KeyValuePair <string, Uri> > list)
            {
                this._currentitem = null;
                this.Meta         = meta;
                string zipfolder = System.IO.Path.Combine(Leayal.AppInfo.AssemblyInfo.DirectoryPath, "translation", meta.SelectedRegion);

                Microsoft.VisualBasic.FileIO.FileSystem.CreateDirectory(zipfolder);
                this.OutputPath = System.IO.Path.Combine(zipfolder, meta.SelectedLanguage + ".zip");
                this.ZipPath    = Path.ChangeExtension(this.OutputPath, "downloading");
                File.Delete(this.ZipPath);
                this.ZipFile = new Ionic.Zip.ZipFile(this.ZipPath, Encoding.UTF8)
                {
                    CompressionMethod = Ionic.Zip.CompressionMethod.Deflate,
                    CompressionLevel  = Ionic.Zlib.CompressionLevel.BestCompression
                };
                if (list != null)
                {
                    this.dict       = new ConcurrentDictionary <string, Uri>(list);
                    this.queue      = new ConcurrentBag <string>(this.dict.Keys);
                    this.TotalCount = this.dict.Count;
                }
                else
                {
                    this.dict       = new ConcurrentDictionary <string, Uri>();
                    this.queue      = new ConcurrentBag <string>();
                    this.TotalCount = 0;
                }
            }
        private void DownloadTXTs(DownloadMeta meta)
        {
            DownloadList dl        = new DownloadList(meta, this.GetFileList(meta));
            var          something = dl.GetNext();

            if (something.HasValue)
            {
                this.OnDownloadBegin(new StringEventArgs(Path.GetFileName(something.Value.Key)));
                this.OnDownloadTranslationProgressChanged(new DownloadTranslationProgressChangedEventArgs(dl.CurrentCount, dl.TotalCount));
                this.myWebClient.DownloadToMemoryAsync(something.Value.Value, something.Value.Key, dl);
            }
        }
 private System.Collections.Generic.Dictionary <string, Uri> GetFileList(DownloadMeta meta)
 {
     TranslationDescription.Description desc;
     System.Collections.Generic.Dictionary <string, Uri> result = new System.Collections.Generic.Dictionary <string, Uri>();
     for (int i = 0; i < meta.TranslationDescription.Descriptions.Length; i++)
     {
         desc = meta.TranslationDescription.Descriptions[i];
         if (desc.TargetData.EndsWith("data12.v", StringComparison.OrdinalIgnoreCase))
         {
             result.Add(desc.PathTXT, new Uri(Leayal.UriHelper.URLConcat(RootURL, meta.SelectedRegion, meta.SelectedLanguage, desc.PathTXT)));
         }
     }
     return(result);
 }
示例#4
0
        public Game([NotNull] string json) : this()
        {
            Json = json ?? throw new ArgumentNullException(nameof(json));

            using JsonDocument jsonDoc = JsonDocument.Parse(json);

            Id = jsonDoc.RootElement.GetProperty("id").GetString();

            Url = jsonDoc.RootElement.TryGetProperty("url", out JsonElement url) ? url.GetString() : "";

            TryParseBuildType(jsonDoc.RootElement.GetProperty("type").GetString(), out BuildType buildType);
            Type = buildType;

            ReleaseTime = jsonDoc.RootElement.GetProperty("releaseTime").GetDateTime();

            Time = jsonDoc.RootElement.GetProperty("time").GetDateTime();

            Dictionary <AppType, DownloadMeta> downloadList = new Dictionary <AppType, DownloadMeta>();

            if (jsonDoc.RootElement.TryGetProperty("downloads", out JsonElement downloads))
            {
                foreach (JsonProperty download in downloads.EnumerateObject())
                {
                    if (!Enum.TryParse(download.Name, true, out AppType appType))
                    {
                        continue;
                    }

                    downloadList[appType] = new DownloadMeta(
                        download.Value.GetProperty("sha1").GetString(),
                        download.Value.GetProperty("size").GetInt64(),
                        download.Value.GetProperty("url").GetString()
                        );
                }
            }

            Downloads = new ReadOnlyDictionary <AppType, DownloadMeta>(downloadList);
        }
        private void MyWebClient_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
        {
            DownloadMeta meta = e.UserState as DownloadMeta;

            if (e.Error != null)
            {
                if (meta != null)
                {
                }
                else
                {
                    DownloadStringStep step = (DownloadStringStep)e.UserState;
                    switch (step)
                    {
                    case DownloadStringStep.CheckForUpdate:
                        this.CheckForTranslationVersionCompleted?.Invoke(this, new CheckForTranslationVersionCompletedEventArgs(e.Error, e.Cancelled, new TranslationVersions(e.Result)));
                        break;
                    }
                }
            }
            else if (e.Cancelled)
            {
                if (meta != null)
                {
                }
                else
                {
                    DownloadStringStep step = (DownloadStringStep)e.UserState;
                    switch (step)
                    {
                    case DownloadStringStep.CheckForUpdate:
                        this.CheckForTranslationVersionCompleted?.Invoke(this, new CheckForTranslationVersionCompletedEventArgs(e.Error, e.Cancelled, new TranslationVersions(e.Result)));
                        break;
                    }
                }
            }
            else
            {
                if (meta != null)
                {
                    switch (meta.Step)
                    {
                    case DownloadStringStep.GetLanguagesData:
                        meta.SetDataEncryption(e.Result);
                        meta.SetStep(DownloadStringStep.GetLanguageDescription);
                        this.myWebClient.DownloadStringAsync(new Uri(Leayal.UriHelper.URLConcat(RootURL, meta.SelectedRegion, meta.SelectedLanguage, "TranslationPackData.ini")), meta);
                        break;

                    case DownloadStringStep.GetLanguageDescription:
                        meta.SetTranslationDescription(e.Result);
                        meta.SetStep(DownloadStringStep.DownloadTXTs);
                        this.DownloadTXTs(meta);
                        break;
                    }
                }
                else
                {
                    DownloadStringStep step = (DownloadStringStep)e.UserState;
                    switch (step)
                    {
                    case DownloadStringStep.CheckForUpdate:
                        this.CheckForTranslationVersionCompleted?.Invoke(this, new CheckForTranslationVersionCompletedEventArgs(e.Error, e.Cancelled, new TranslationVersions(e.Result)));
                        break;
                    }
                }
            }
        }