Exemplo n.º 1
0
        public ModVM(NexusDownloader.State m)
        {
            this.ModName         = NexusApiUtils.FixupSummary(m.ModName);
            this.ModID           = m.ModID;
            this.ModDescription  = NexusApiUtils.FixupSummary(m.Summary);
            this.ModAuthor       = NexusApiUtils.FixupSummary(m.Author);
            this.IsNSFW          = m.Adult;
            this.ModURL          = m.NexusURL;
            this.ImageURL        = m.SlideShowPic;
            this.ImageObservable = Observable.Return(this.ImageURL)
                                   .ObserveOn(RxApp.TaskpoolScheduler)
                                   .SelectTask(async url =>
            {
                try
                {
                    var ret = new MemoryStream();
                    using (Stream stream = await new HttpClient().GetStreamAsync(url))
                    {
                        stream.CopyTo(ret);
                    }

                    ret.Seek(0, SeekOrigin.Begin);
                    return(ret);
                }
                catch (Exception ex)
                {
                    Utils.LogToFile($"Exception while caching slide {this.ModName} ({this.ModID})\n{ex.ExceptionToString()}");
                    return(default(MemoryStream));
                }
            })
                                   .ObserveOn(RxApp.MainThreadScheduler)
                                   .Select(memStream =>
            {
                if (memStream == null)
                {
                    return(default(BitmapImage));
                }
                try
                {
                    var image = new BitmapImage();
                    image.BeginInit();
                    image.CacheOption  = BitmapCacheOption.OnLoad;
                    image.StreamSource = memStream;
                    image.EndInit();
                    image.Freeze();
                    return(image);
                }
                catch (Exception ex)
                {
                    Utils.LogToFile($"Exception while caching slide {this.ModName} ({this.ModID})\n{ex.ExceptionToString()}");
                    return(default(BitmapImage));
                }
                finally
                {
                    memStream?.Dispose();
                }
            })
                                   .Replay(1)
                                   .RefCount();
        }
Exemplo n.º 2
0
        public async Task <AbstractDownloadState?> GetDownloaderState(dynamic archiveINI, bool quickMode)
        {
            var general = archiveINI.General;

            if (general.modID != null && general.fileID != null && general.gameName != null)
            {
                var game = GameRegistry.GetByFuzzyName((string)general.gameName).Game;

                if (quickMode)
                {
                    return(new State
                    {
                        Game = GameRegistry.GetByFuzzyName((string)general.gameName).Game,
                        ModID = long.Parse(general.modID),
                        FileID = long.Parse(general.fileID),
                    });
                }

                var client = DownloadDispatcher.GetInstance <NexusDownloader>().Client ?? await NexusApiClient.Get();

                ModInfo info;
                try
                {
                    info = await client.GetModInfo(game, long.Parse((string)general.modID));
                }
                catch (Exception)
                {
                    return(new State
                    {
                        Game = GameRegistry.GetByFuzzyName((string)general.gameName).Game,
                        ModID = long.Parse(general.modID),
                        FileID = long.Parse(general.fileID),
                    });
                }

                try
                {
                    return(new State
                    {
                        Name = NexusApiUtils.FixupSummary(info.name),
                        Author = NexusApiUtils.FixupSummary(info.author),
                        Version = general.version ?? "0.0.0.0",
                        ImageURL = info.picture_url,
                        IsNSFW = info.contains_adult_content,
                        Description = NexusApiUtils.FixupSummary(info.summary),
                        Game = GameRegistry.GetByFuzzyName((string)general.gameName).Game,
                        ModID = long.Parse(general.modID),
                        FileID = long.Parse(general.fileID)
                    });
                }
                catch (FormatException)
                {
                    Utils.Log(
                        $"Cannot parse ModID/FileID from {(string)general.gameName} {(string)general.modID} {(string)general.fileID}");
                    throw;
                }
            }

            return(null);
        }
Exemplo n.º 3
0
        public ModVM(NexusDownloader.State m)
        {
            ModName         = NexusApiUtils.FixupSummary(m.ModName);
            ModID           = m.ModID;
            ModDescription  = NexusApiUtils.FixupSummary(m.Summary);
            ModAuthor       = NexusApiUtils.FixupSummary(m.Author);
            IsNSFW          = m.Adult;
            ModURL          = m.NexusURL;
            ImageURL        = m.SlideShowPic;
            ImageObservable = Observable.Return(ImageURL)
                              .ObserveOn(RxApp.TaskpoolScheduler)
                              .SelectTask(async url =>
            {
                try
                {
                    var ret = new MemoryStream();
                    using (Stream stream = await new HttpClient().GetStreamAsync(url))
                    {
                        stream.CopyTo(ret);
                    }

                    ret.Seek(0, SeekOrigin.Begin);
                    return(ret);
                }
                catch (Exception ex)
                {
                    Utils.Error(ex, $"Exception while caching slide {ModName} ({ModID})");
                    return(default(MemoryStream));
                }
            })
                              .ObserveOn(RxApp.MainThreadScheduler)
                              .Select(memStream =>
            {
                if (memStream == null)
                {
                    return(default(BitmapImage));
                }
                try
                {
                    return(UIUtils.BitmapImageFromStream(memStream));
                }
                catch (Exception ex)
                {
                    Utils.Error(ex, $"Exception while caching slide {ModName} ({ModID})");
                    return(default(BitmapImage));
                }
                finally
                {
                    memStream?.Dispose();
                }
            })
                              .Replay(1)
                              .RefCount();
        }
Exemplo n.º 4
0
 public ModVM(NexusDownloader.State m)
 {
     ModName         = NexusApiUtils.FixupSummary(m.ModName);
     ModID           = m.ModID;
     ModDescription  = NexusApiUtils.FixupSummary(m.Summary);
     ModAuthor       = NexusApiUtils.FixupSummary(m.Author);
     IsNSFW          = m.Adult;
     ModURL          = m.NexusURL;
     ImageURL        = m.SlideShowPic;
     ImageObservable = Observable.Return(ImageURL)
                       .ObserveOn(RxApp.TaskpoolScheduler)
                       .DownloadBitmapImage((ex) => Utils.Log($"Skipping slide for mod {ModName} ({ModID})"))
                       .Replay(1)
                       .RefCount(TimeSpan.FromMilliseconds(5000));
 }
Exemplo n.º 5
0
        public async Task <AbstractDownloadState?> GetDownloaderState(dynamic archiveINI, bool quickMode)
        {
            var general = archiveINI.General;

            if (general.modID != null && general.fileID != null && general.gameName != null)
            {
                var game = GameRegistry.GetByFuzzyName((string)general.gameName).Game;
                if (quickMode)
                {
                    return(new State
                    {
                        Game = GameRegistry.GetByFuzzyName((string)general.gameName).Game,
                        ModID = long.Parse(general.modID),
                        FileID = long.Parse(general.fileID),
                    });
                }

                var client = await NexusApiClient.Get();

                ModInfo info;
                try
                {
                    info = await client.GetModInfo(game, long.Parse((string)general.modID));
                }
                catch (Exception)
                {
                    Utils.Error($"Error getting mod info for Nexus mod with {general.modID}");
                    throw;
                }

                return(new State
                {
                    Name = NexusApiUtils.FixupSummary(info.name),
                    Author = NexusApiUtils.FixupSummary(info.author),
                    Version = general.version ?? "0.0.0.0",
                    ImageURL = info.picture_url,
                    IsNSFW = info.contains_adult_content,
                    Description = NexusApiUtils.FixupSummary(info.summary),
                    Game = GameRegistry.GetByFuzzyName((string)general.gameName).Game,
                    ModID = long.Parse(general.modID),
                    FileID = long.Parse(general.fileID)
                });
            }

            return(null);
        }