private void btnInstallStlServer_Click(object sender, EventArgs e)
        {
            try
            {
                ThumbnailProvider.RegisterExtension(typeof(StlThumbnailProvider));
                MessageBox.Show("Registration done with RegisterExtension ");
            }
            catch (Exception ex1)
            {
                MessageBox.Show(@"Got priviledge problems. Tries another solution" + Environment.NewLine + ex1.Message);
                try
                {
                    Register();
                }
                catch (Exception ex2)
                {
                    MessageBox.Show(@"Tried to run as Administrator and even that attempt failed" + Environment.NewLine +
                                    ex2.Message);
                }
            }

            try
            {
                Register();
                MessageBox.Show("Registration done with Shell Register ");
            }
            catch (Exception ex3)
            {
                MessageBox.Show(@"Registration thru CMD failed. Registration must be don manually " +
                                Environment.NewLine + ex3.Message);
            }
        }
        private void btnUnInstallStlServer_Click(object sender, EventArgs e)
        {
            try
            {
                ThumbnailProvider.UnRegisterExtension(typeof(StlThumbnailProvider));
                MessageBox.Show(@"UnRegistration done with UnRegisterExtension ");
            }
            catch (Exception)
            {
                MessageBox.Show(@"Got priviledge problems. Tries another solution");
                try
                {
                    UnRegister();
                }
                catch (Exception)
                {
                    MessageBox.Show(@"Tried to run as Administrator and even that attempt failed");
                }
            }

            try
            {
                UnRegister();
                MessageBox.Show(@"Registration done with Shell UnRegister ");
            }
            catch (Exception)
            {
                MessageBox.Show(@"UnRegistration thru CMD failed. Registration must be don manually");
            }
        }
Exemple #3
0
        // thanks BCES00569
        public static async Task <List <DiscordEmbedBuilder> > AsEmbedAsync(this TitlePatch patch, DiscordClient client, string productCode)
        {
            var result = new List <DiscordEmbedBuilder>();
            var pkgs   = patch?.Tag?.Packages;
            var title  = pkgs?.Select(p => p.ParamSfo?.Title).LastOrDefault(t => !string.IsNullOrEmpty(t))
                         ?? await ThumbnailProvider.GetTitleNameAsync(productCode, Config.Cts.Token).ConfigureAwait(false)
                         ?? productCode;

            var thumbnailUrl = await client.GetThumbnailUrlAsync(productCode).ConfigureAwait(false);

            var embedBuilder = new DiscordEmbedBuilder
            {
                Title = title,
                Color = Config.Colors.DownloadLinks,
            }.WithThumbnail(thumbnailUrl);

            if (pkgs?.Length > 1)
            {
                var pages = pkgs.Length / EmbedPager.MaxFields + (pkgs.Length % EmbedPager.MaxFields == 0 ? 0 : 1);
                if (pages > 1)
                {
                    embedBuilder.Title = $"{title} [Part 1 of {pages}]".Trim(EmbedPager.MaxFieldTitleLength);
                }
                embedBuilder.Description = $"Total download size of all {pkgs.Length} packages is {pkgs.Sum(p => p.Size).AsStorageUnit()}";
                var i = 0;
                do
                {
                    var pkg = pkgs[i++];
                    embedBuilder.AddField($"Update v{pkg.Version} ({pkg.Size.AsStorageUnit()})", $"[⏬ {GetLinkName(pkg.Url)}]({pkg.Url})");
                    if (i % EmbedPager.MaxFields == 0)
                    {
                        result.Add(embedBuilder);
                        embedBuilder = new DiscordEmbedBuilder
                        {
                            Title = $"{title} [Part {i / EmbedPager.MaxFields + 1} of {pages}]".Trim(EmbedPager.MaxFieldTitleLength),
                            Color = Config.Colors.DownloadLinks,
                        }.WithThumbnail(thumbnailUrl);
                    }
                } while (i < pkgs.Length);
            }
            else if (pkgs?.Length == 1)
            {
                embedBuilder.Title       = $"{title} update v{pkgs[0].Version} ({pkgs[0].Size.AsStorageUnit()})";
                embedBuilder.Description = $"[⏬ {Path.GetFileName(GetLinkName(pkgs[0].Url))}]({pkgs[0].Url})";
            }
            else if (patch != null)
            {
                embedBuilder.Description = "No updates available";
            }
            else
            {
                embedBuilder.Description = "No update information available";
            }
            if (!result.Any() || embedBuilder.Fields.Any())
            {
                result.Add(embedBuilder);
            }
            return(result);
        }
Exemple #4
0
        private Stream GetDocumentThumbnail(string filePath, int width, int height)
        {
            var thumbnail = ThumbnailProvider.GetThumbnail(filePath, width, height, ThumbnailOptions.None);

            var result = new MemoryStream();

            thumbnail.Save(result, System.Drawing.Imaging.ImageFormat.Png);

            return(result);
        }
Exemple #5
0
 public Icon ExtractIcon(ThumbnailProvider thumbnailProvider)
 {
     if (Type == EntryType.File)
     {
         if (thumbnailProvider.IsSupported(Path))
         {
             return(thumbnailProvider.GenerateThumbnail(Path));
         }
         else
         {
             return(Icon.ExtractAssociatedIcon(Path));
         }
     }
     else
     {
         return(IconUtil.FolderLarge);
     }
 }
Exemple #6
0
        private async void FileLister_PathChanged(string value)
        {
            if (value != null)
            {
                try
                {
                    Thumbnail = await Task.Factory.StartNew(() => ThumbnailProvider.GetThumbnailSource(value, 32, 32, ThumbnailOptions.IconOnly));

                    _watcher?.ObservePath(value);
                }
                catch (Exception)
                {
                    //ignore
                }
            }

            if (string.IsNullOrEmpty(value))
            {
                PathName = Constants.RootName;
            }
            else
            {
                var uri = new Uri(value);
                if (uri.IsUnc && uri.Segments.Length == 1)
                {
                    PathName = value;
                }
                else if (!uri.IsUnc && new DirectoryInfo(value).Parent == null)
                {
                    PathName = $"Drive {value}";
                }
                else
                {
                    PathName = System.IO.Path.GetFileName(value);
                }
            }

            Title = value;
        }
Exemple #7
0
        protected override async Task <BitmapSource> GetThumbnail()
        {
            ThumbMaxHeight = 80;
            if (Item.IsFileShare)
            {
                var thumb = Utils.GetImageFromRessource("share.png");
                thumb.Freeze();
                return(thumb);
            }

            if (Item.IsNetwork())
            {
                return(Item.Details.Thumbnail);
            }

            if (IsPicture)
            {
                ThumbMaxHeight = 120;
            }

            return(await ThumbnailProvider.GetLargeThumbnailAsync(Item.Path).ConfigureAwait(false));
        }
 public static DiscordEmbedBuilder AsEmbed(this TitleInfo info, string titleId, string gameTitle = null, bool forLog = false, string thumbnailUrl = null)
 {
     if (string.IsNullOrWhiteSpace(gameTitle))
     {
         gameTitle = null;
     }
     if (StatusColors.TryGetValue(info.Status, out var color))
     {
         // apparently there's no formatting in the footer, but you need to escape everything in description; ugh
         var productCodePart = string.IsNullOrWhiteSpace(titleId) ? "" : $"[{titleId}] ";
         var onlineOnlypart  = info.Network == true ? " 🌐" : "";
         var pr   = info.ToPrString(null, true);
         var desc = $"{info.Status} since {info.ToUpdated() ?? "forever"}";
         if (pr != null)
         {
             desc += $" (PR {pr})";
         }
         if (!forLog && !string.IsNullOrEmpty(info.AlternativeTitle))
         {
             desc = info.AlternativeTitle + Environment.NewLine + desc;
         }
         if (!string.IsNullOrEmpty(info.WikiTitle))
         {
             desc += $"{(forLog ? ", " : Environment.NewLine)}[Wiki Page](https://wiki.rpcs3.net/index.php?title={info.WikiTitle})";
         }
         var cacheTitle = info.Title ?? gameTitle;
         if (!string.IsNullOrEmpty(cacheTitle))
         {
             StatsStorage.GameStatCache.TryGetValue(cacheTitle, out int stat);
             StatsStorage.GameStatCache.Set(cacheTitle, ++stat, StatsStorage.CacheTime);
         }
         var title = $"{productCodePart}{cacheTitle.Trim(200)}{onlineOnlypart}";
         if (string.IsNullOrEmpty(title))
         {
             desc = "";
         }
         return(new DiscordEmbedBuilder
         {
             Title = title,
             Url = info.Thread > 0 ? $"https://forums.rpcs3.net/thread-{info.Thread}.html" : null,
             Description = desc,
             Color = color,
         }.WithThumbnail(thumbnailUrl));
     }
     else
     {
         var desc       = "";
         var embedColor = Config.Colors.Maintenance;
         if (info.Status == TitleInfo.Maintenance.Status)
         {
             desc = "API is undergoing maintenance, please try again later.";
         }
         else if (info.Status == TitleInfo.CommunicationError.Status)
         {
             desc = "Error communicating with compatibility API, please try again later.";
         }
         else
         {
             embedColor = Config.Colors.CompatStatusUnknown;
             if (!string.IsNullOrEmpty(titleId))
             {
                 desc = $"Product code {titleId} was not found in compatibility database";
             }
         }
         var result = new DiscordEmbedBuilder
         {
             Description = desc,
             Color       = embedColor,
         }.WithThumbnail(thumbnailUrl);
         if (gameTitle == null &&
             ThumbnailProvider.GetTitleNameAsync(titleId, Config.Cts.Token).ConfigureAwait(false).GetAwaiter().GetResult() is string titleName &&
             !string.IsNullOrEmpty(titleName))
         {
             gameTitle = titleName;
         }
         if (!string.IsNullOrEmpty(gameTitle))
         {
             StatsStorage.GameStatCache.TryGetValue(gameTitle, out int stat);
             StatsStorage.GameStatCache.Set(gameTitle, ++stat, StatsStorage.CacheTime);
             var productCodePart = string.IsNullOrEmpty(titleId) ? "" : $"[{titleId}] ";
             result.Title = $"{productCodePart}{gameTitle.Sanitize().Trim(200)}";
         }
         return(result);
     }
 }
Exemple #9
0
        public static async Task OnMessageDeleted(MessageDeleteEventArgs e)
        {
            if (e.Channel.IsPrivate)
            {
                return;
            }

            var msg = e.Message;

            if (msg?.Author == null)
            {
                return;
            }

            if (msg.Author.IsCurrent || msg.Author.IsBotSafeCheck())
            {
                return;
            }

            if (RemovedByBotCache.TryGetValue(msg.Id, out _))
            {
                return;
            }

            var usernameWithNickname = msg.Author.GetUsernameWithNickname(e.Client, e.Guild);
            var logMsg = msg.Content;

            if (msg.Attachments.Any())
            {
                logMsg += Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, msg.Attachments.Select(a => $"📎 {a.FileName}"));
            }
            Config.Log.Info($"Deleted message from {usernameWithNickname} ({msg.JumpLink}):{Environment.NewLine}{logMsg.TrimStart()}");

            var logChannel = await e.Client.GetChannelAsync(Config.DeletedMessagesLogChannelId).ConfigureAwait(false);

            if (logChannel == null)
            {
                return;
            }

            var(attachmentContent, attachmentFilenames) = await msg.DownloadAttachmentsAsync().ConfigureAwait(false);

            try
            {
                var embed = new DiscordEmbedBuilder()
                            .WithAuthor($"{msg.Author.Username}#{msg.Author.Discriminator} in #{msg.Channel.Name}", iconUrl: msg.Author.AvatarUrl)
                            .WithDescription(msg.JumpLink.ToString())
                            .WithFooter($"Post date: {msg.Timestamp:yyyy-MM-dd HH:mm:ss} ({(DateTime.UtcNow - msg.Timestamp).AsTimeDeltaDescription()} ago)");
                if (attachmentFilenames?.Count > 0)
                {
                    embed.AddField("Deleted Attachments", string.Join('\n', msg.Attachments.Select(a => $"📎 {a.FileName}")));
                }
                var color = await ThumbnailProvider.GetImageColorAsync(msg.Author.AvatarUrl).ConfigureAwait(false);

                if (color.HasValue)
                {
                    embed.WithColor(color.Value);
                }
                await postLock.WaitAsync().ConfigureAwait(false);

                try
                {
                    await logChannel.SendMessageAsync(embed : embed, mentions : Config.AllowedMentions.Nothing).ConfigureAwait(false);

                    if (attachmentContent?.Count > 0)
                    {
                        await logChannel.SendMultipleFilesAsync(attachmentContent, msg.Content, mentions : Config.AllowedMentions.Nothing).ConfigureAwait(false);
                    }
                    else if (!string.IsNullOrEmpty(msg.Content))
                    {
                        await logChannel.SendMessageAsync(msg.Content, mentions : Config.AllowedMentions.Nothing).ConfigureAwait(false);
                    }
                }
                finally
                {
                    postLock.Release();
                }
            }
            finally
            {
                if (attachmentContent?.Count > 0)
                {
                    foreach (var f in attachmentContent.Values)
                    {
                        f.Dispose();
                    }
                }
            }
        }
Exemple #10
0
 protected override Task <BitmapSource> GetThumbnail()
 {
     return(ThumbnailProvider.GetLargeThumbnailAsync(Item?.AssemblyPath));
 }
Exemple #11
0
        public static async Task SearchForGame(CommandContext ctx, string search, int maxResults)
        {
            var ch = await ctx.GetChannelForSpamAsync().ConfigureAwait(false);

            DiscordMessage msg = null;

            try
            {
                if (string.IsNullOrEmpty(search))
                {
                    var interact = ctx.Client.GetInteractivity();
                    msg = await msg.UpdateOrCreateMessageAsync(ch, "What game are you looking for?").ConfigureAwait(false);

                    var response = await interact.WaitForMessageAsync(m => m.Author == ctx.User && m.Channel == ch).ConfigureAwait(false);

                    await msg.DeleteAsync().ConfigureAwait(false);

                    msg = null;
                    if (string.IsNullOrEmpty(response.Result?.Content))
                    {
                        await ctx.ReactWithAsync(Config.Reactions.Failure).ConfigureAwait(false);

                        return;
                    }

                    search = response.Result.Content;
                }

                string titleId    = null;
                var    productIds = ProductCodeLookup.GetProductIds(search);
                if (productIds.Count > 0)
                {
                    using (var db = new ThumbnailDb())
                    {
                        var contentId = await db.Thumbnail.FirstOrDefaultAsync(t => t.ProductCode == productIds[0].ToUpperInvariant()).ConfigureAwait(false);

                        if (contentId?.ContentId != null)
                        {
                            titleId = contentId.ContentId;
                        }
                        if (contentId?.Name != null)
                        {
                            search = contentId.Name;
                        }
                    }
                }

                var alteredSearch = search.Trim();
                if (alteredSearch.EndsWith("demo", StringComparison.InvariantCultureIgnoreCase))
                {
                    alteredSearch = alteredSearch.Substring(0, alteredSearch.Length - 4).TrimEnd();
                }
                if (alteredSearch.EndsWith("trial", StringComparison.InvariantCultureIgnoreCase))
                {
                    alteredSearch = alteredSearch.Substring(0, alteredSearch.Length - 5).TrimEnd();
                }
                if (alteredSearch.EndsWith("体験版"))
                {
                    alteredSearch = alteredSearch.Substring(0, alteredSearch.Length - 3).TrimEnd();
                }

                if (string.IsNullOrEmpty(alteredSearch))
                {
                    alteredSearch = search;
                }
                var msgTask           = msg.UpdateOrCreateMessageAsync(ch, "⏳ Searching...");
                var psnResponseUSTask = titleId == null?Client.SearchAsync("en-US", alteredSearch, Config.Cts.Token) : Client.ResolveContentAsync("en-US", titleId, 1, Config.Cts.Token);

                var psnResponseEUTask = titleId == null?Client.SearchAsync("en-GB", alteredSearch, Config.Cts.Token) : Client.ResolveContentAsync("en-GB", titleId, 1, Config.Cts.Token);

                var psnResponseJPTask = titleId == null?Client.SearchAsync("ja-JP", alteredSearch, Config.Cts.Token) : Client.ResolveContentAsync("ja-JP", titleId, 1, Config.Cts.Token);

                await Task.WhenAll(msgTask, psnResponseUSTask, psnResponseEUTask, psnResponseJPTask).ConfigureAwait(false);

                var responseUS = await psnResponseUSTask.ConfigureAwait(false);

                var responseEU = await psnResponseEUTask.ConfigureAwait(false);

                var responseJP = await psnResponseJPTask.ConfigureAwait(false);

                msg = await msgTask.ConfigureAwait(false);

                msg = await msg.UpdateOrCreateMessageAsync(ch, "⌛ Preparing results...").ConfigureAwait(false);

                var usGames      = GetBestMatch(responseUS?.Included, search, maxResults) ?? EmptyMatch;
                var euGames      = GetBestMatch(responseEU?.Included, search, maxResults) ?? EmptyMatch;
                var jpGames      = GetBestMatch(responseJP?.Included, search, maxResults) ?? EmptyMatch;
                var combinedList = usGames.Select(g => (g, "US", "en-US"))
                                   .Concat(euGames.Select(g => (g, "EU", "en-GB")))
                                   .Concat(jpGames.Select(g => (g, "JP", "ja-JP")))
                                   .ToList();
                combinedList = GetSortedList(combinedList, search, maxResults);
                var hasResults = false;
                foreach (var(g, region, locale) in combinedList)
                {
                    if (g == null)
                    {
                        continue;
                    }

                    var thumb = await ThumbnailProvider.GetThumbnailUrlWithColorAsync(ctx.Client, g.Id, PsnBlue, g.Attributes.ThumbnailUrlBase).ConfigureAwait(false);

                    string score;
                    if ((g.Attributes.StarRating?.Score ?? 0m) == 0m || (g.Attributes.StarRating?.Total ?? 0) == 0)
                    {
                        score = "N/A";
                    }
                    else
                    {
                        if (ctx.User.Id == 247291873511604224ul)
                        {
                            score = StringUtils.GetStars(g.Attributes.StarRating?.Score);
                        }
                        else
                        {
                            score = StringUtils.GetMoons(g.Attributes.StarRating?.Score);
                        }
                        score = $"{score} ({g.Attributes.StarRating?.Score} by {g.Attributes.StarRating.Total} people)";
                    }
                    string fileSize = null;
                    if (g.Attributes.FileSize?.Value.HasValue ?? false)
                    {
                        fileSize = g.Attributes.FileSize.Value.ToString();
                        if (g.Attributes.FileSize?.Unit is string unit && !string.IsNullOrEmpty(unit))
                        {
                            fileSize += " " + unit;
                        }
                        else
                        {
                            fileSize += " GB";
                        }
                        fileSize = $" ({fileSize})";
                    }

                    //var instructions = g.Attributes.TopCategory == "disc_based_game" ? "dumping_procedure" : "software_distribution";
                    var result = new DiscordEmbedBuilder
                    {
                        Color       = thumb.color,
                        Title       = $"⏬ {g.Attributes.Name?.StripMarks()} [{region}]{fileSize}",
                        Url         = $"https://store.playstation.com/{locale}/product/{g.Id}",
                        Description = $"Rating: {score}\n" +
                                      "[Instructions](https://rpcs3.net/quickstart#software_distribution)",
                        ThumbnailUrl = thumb.url,
                    };
                    await ProductCodeLookup.FixAfrikaAsync(ctx.Client, ctx.Message, result).ConfigureAwait(false);

#if DEBUG
                    result.WithFooter("Test instance");
#endif
                    hasResults = true;
                    await ch.SendMessageAsync(embed : result).ConfigureAwait(false);
                }
                if (hasResults)
                {
                    await msg.DeleteAsync().ConfigureAwait(false);
                }
                else
                {
                    await msg.UpdateOrCreateMessageAsync(ch, "No results").ConfigureAwait(false);
                }
            }
Exemple #12
0
        public static DiscordEmbedBuilder AsEmbed(this TitleInfo info, string titleId, string gameTitle = null, bool forLog = false, string thumbnailUrl = null)
        {
            if (info.Status == TitleInfo.Maintenance.Status)
            {
                return new DiscordEmbedBuilder {
                           Description = "API is undergoing maintenance, please try again later.", Color = Config.Colors.Maintenance
                }
            }
            ;

            if (info.Status == TitleInfo.CommunicationError.Status)
            {
                return new DiscordEmbedBuilder {
                           Description = "Error communicating with compatibility API, please try again later.", Color = Config.Colors.Maintenance
                }
            }
            ;

            if (string.IsNullOrWhiteSpace(gameTitle))
            {
                gameTitle = null;
            }

            if (StatusColors.TryGetValue(info.Status, out var color))
            {
                // apparently there's no formatting in the footer, but you need to escape everything in description; ugh
                var productCodePart = string.IsNullOrWhiteSpace(titleId) ? "" : $"[{titleId}] ";
                var pr   = info.ToPrString(null, true);
                var desc = $"{info.Status} since {info.ToUpdated()}";
                if (pr is string _)
                {
                    desc += $" (PR {pr})";
                }
                if (!forLog && !string.IsNullOrEmpty(info.AlternativeTitle))
                {
                    desc = info.AlternativeTitle + Environment.NewLine + desc;
                }
                if (!string.IsNullOrEmpty(info.WikiTitle))
                {
                    desc += $"{(forLog ? ", " : Environment.NewLine)}[Wiki Page](https://wiki.rpcs3.net/index.php?title={info.WikiTitle})";
                }
                return(new DiscordEmbedBuilder
                {
                    Title = $"{productCodePart}{(gameTitle ?? info.Title).Trim(200)}",
                    Url = $"https://forums.rpcs3.net/thread-{info.Thread}.html",
                    Description = desc,
                    Color = color,
                    ThumbnailUrl = thumbnailUrl
                });
            }
            else
            {
                var desc = "";
                if (!string.IsNullOrEmpty(titleId))
                {
                    desc = $"Product code {titleId} was not found in compatibility database";
                }
                var result = new DiscordEmbedBuilder
                {
                    Description  = desc,
                    Color        = Config.Colors.CompatStatusUnknown,
                    ThumbnailUrl = thumbnailUrl,
                };

                if (gameTitle == null && ThumbnailProvider.GetTitleName(titleId) is string titleName && !string.IsNullOrEmpty(titleName))
                {
                    gameTitle = titleName;
                }
                if (!string.IsNullOrEmpty(gameTitle))
                {
                    var productCodePart = string.IsNullOrEmpty(titleId) ? "" : $"[{titleId}] ";
                    result.Title = $"{productCodePart}{gameTitle.Sanitize().Trim(200)}";
                }
                return(result);
            }
        }
Exemple #13
0
 protected override Task <BitmapSource> GetThumbnail()
 {
     return(ThumbnailProvider.GetLargeThumbnailAsync(Item.FileName));
 }