Ejemplo n.º 1
0
        protected static void OutputHtml(AllInfo data)
        {
            var mainFile  = "index.html";
            var gamesFile = "games.html";

            var files = new Dictionary <string, string>
            {
                [mainFile] = OutputMain(data),
                [mainFile] = OutputGames(data),
            };

            var vars = new Dictionary <string, string>
            {
                ["time"]      = DateTimeOffset.Now.ToString(),
                ["filemain"]  = mainFile,
                ["filegames"] = gamesFile
            };

            var dirname = $"output";

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

            foreach (var kv in files)
            {
                File.WriteAllText(Path.Combine(dirname, kv.Key), kv.Value);
            }

            Console.WriteLine("HTML-output done");
        }
Ejemplo n.º 2
0
        protected static string OutputGames(AllInfo data)
        {
            var vars = new Dictionary <string, string>
            {
            };

            return(ProcessTemplate("games", vars));
        }
Ejemplo n.º 3
0
        protected static void OutputCSV(AllInfo data)
        {
            var sb = new StringBuilder();

            var cums = new Dictionary <string, int>();

            sb.Append($"DAY");

            foreach (var key in data.AppType.Keys)
            {
                cums[$"{key}_free"]            = 0;
                cums[$"{key}_free_cumulative"] = 0;
                cums[$"{key}_paid"]            = 0;
                cums[$"{key}_paid_cumulative"] = 0;

                sb.Append($";{key}_free;{key}_free_cumulative");
                sb.Append($";{key}_paid;{key}_paid_cumulative");
            }

            sb.AppendLine();

            foreach (var day in data.Days)
            {
                sb.Append($"{day.Key.ToShortDateString()}");

                foreach (var kv in data.AppType)
                {
                    if (!kv.Value.Days.ContainsKey(day.Key))
                    {
                        // No activations in current day
                        var cumufree = cums[$"{kv.Key}_free"];
                        var cumupaid = cums[$"{kv.Key}_free"];

                        sb.Append($";0;{cumufree};0;{cumupaid}");

                        continue;
                    }

                    var typeDay = kv.Value.Days[day.Key];

                    sb.Append($";{typeDay.Free};{typeDay.FreeCumulative};{typeDay.Paid};{typeDay.PaidCumulative}");
                }

                sb.AppendLine();
            }

            File.WriteAllText("games.csv", sb.ToString());

            Console.WriteLine("Written to games.csv");
        }
Ejemplo n.º 4
0
        static async Task Main(string[] args)
        {
            var outputsTodo = new List <string>();

            if (args.Length == 1)
            {
                outputsTodo.AddRange(args[0].Split(','));
            }
            else if (args.Length != 0)
            {
                Console.WriteLine("Unknown number of arguments");
                return;
            }
            else
            {
                outputsTodo.Add("csv");
            }

            Outputs.Add("csv", OutputCSV);
            Outputs.Add("html", OutputHtml);

            if (outputsTodo.Any(x => !Outputs.ContainsKey(x)))
            {
                Console.WriteLine("Unknown output of arguments");
                return;
            }

            Console.Write("Username: "******"Password: "******"Connecting ");
            await conn.ConnectAsync();

            Console.WriteLine("Connected ");

            var res = await conn.PICSReady;

            if (!res)
            {
                Console.WriteLine("Error. Failed to get metainfo.");
                Environment.Exit(1);
            }

            var appsOwned     = new List <uint>();
            var appsOwnedFree = new List <uint>();

            var uniqueLicenseFlags = new HashSet <string>();

            var data = new AllInfo();

            foreach (var license in conn.Licenses.Where(x => !x.LicenseFlags.HasFlag(ELicenseFlags.Expired)).OrderBy(x => x.TimeCreated))
            {
                var date = license.TimeCreated.Date;

                if (data.CurrentDay == null || data.CurrentDay.Date != date)
                {
                    var nextDay = data.CurrentDay?.Date.AddDays(1) ?? date;

                    // Fill gaps
                    while (nextDay <= date)
                    {
                        data.Days[nextDay] = new TypeDay
                        {
                            Date           = nextDay,
                            FreeCumulative = data.CurrentDay?.FreeCumulative ?? 0,
                            PaidCumulative = data.CurrentDay?.PaidCumulative ?? 0,
                        };
                        nextDay = nextDay.AddDays(1);
                    }

                    data.CurrentDay = data.Days[date];
                }

                // Skip Family Sharing
                if (license.PaymentMethod == EPaymentMethod.AuthorizedDevice)
                {
                    continue;
                }

                var fl = (license.LicenseFlags & ~ELicenseFlags.RegionRestrictionExpired).ToString();

                if (!uniqueLicenseFlags.Contains(fl))
                {
                    uniqueLicenseFlags.Add(fl);
                }

                var package = conn.Packages[license.PackageID];

                var typesPackage = new List <string>();

                var isfree = TemporaryTypes.Contains(package.BillingType) || package.ID == 0;

                foreach (var appid in package.Apps)
                {
                    if (!isfree && appsOwned.Contains(appid))
                    {
                        continue;
                    }
                    else if (isfree && appsOwnedFree.Contains(appid))
                    {
                        continue;
                    }

                    (isfree ? appsOwnedFree : appsOwned).Add(appid);

                    var app = conn.Apps[appid];

                    var appType = app?.Type ?? "unknown";

                    if (!data.AppType.ContainsKey(appType))
                    {
                        data.AppType[appType] = new TypeInfo
                        {
                            Type = appType,
                        };
                    }

                    var typeInfo = data.AppType[appType];

                    if (typeInfo.CurrentDay == null || typeInfo.CurrentDay.Date != date)
                    {
                        var nextDay = typeInfo.CurrentDay?.Date.AddDays(1) ?? date;

                        // Fill gaps
                        while (nextDay <= date)
                        {
                            typeInfo.Days[nextDay] = new TypeDay
                            {
                                Date           = nextDay,
                                FreeCumulative = typeInfo.CurrentDay?.FreeCumulative ?? 0,
                                PaidCumulative = typeInfo.CurrentDay?.PaidCumulative ?? 0,
                            };
                            nextDay = nextDay.AddDays(1);
                        }

                        typeInfo.CurrentDay = typeInfo.Days[date];
                    }

                    if (isfree)
                    {
                        // Global Total
                        data.CurrentDay.Free++;
                        data.CurrentDay.FreeCumulative++;

                        // This Type
                        typeInfo.CurrentDay.Free++;
                        typeInfo.CurrentDay.FreeCumulative++;
                    }
                    else
                    {
                        // Global Total
                        data.CurrentDay.Paid++;
                        data.CurrentDay.PaidCumulative++;

                        // This Type
                        typeInfo.CurrentDay.Paid++;
                        typeInfo.CurrentDay.PaidCumulative++;
                    }
                }
            }

            foreach (var format in outputsTodo)
            {
                Outputs[format](data);
            }

            Environment.Exit(0);
        }