Exemplo n.º 1
0
        public void Can_Compare_Two_Dates_Regardless_Of_Precedence()
        {
            var from = new DateTime(2000, 1, 1);
            var to   = new DateTime(2001, 1, 1);

            var duration = new PrettyTime(from).Format(to);

            Assert.AreEqual("1 year from now", duration);
        }
Exemplo n.º 2
0
        public void Can_Compare_Two_Dates()
        {
            var from = new DateTime(2000, 1, 1);
            var to   = new DateTime(2001, 1, 1);

            var duration = new PrettyTime(to).Format(from);

            Assert.AreEqual("1 year ago", duration);
        }
Exemplo n.º 3
0
        public void Can_Format_Seconds(int seconds, string expected, string cultureName)
        {
            using (var context = new CultureSwitchContext(new CultureInfo(cultureName)))
            {
                var date   = DateTime.Now.AddSeconds(seconds);
                var pretty = new PrettyTime();

                var result = pretty.Format(date);

                Assert.NotNull(result);
                Assert.AreEqual(expected, result);
            }
        }
Exemplo n.º 4
0
        static void testPrettyTime()
        {
            var st2   = PrettyTime.Format(DateTime.Now.AddDays(1).AddHours(1));
            var st32  = PrettyTime.Format(DateTime.Now.AddHours(23));
            var st22  = PrettyTime.Format(DateTime.Now.AddDays(2));
            var st356 = PrettyTime.Format(DateTime.Now.AddHours(33));

            var st3  = PrettyTime.Format(DateTime.Now.AddHours(-23));
            var st   = PrettyTime.Format(DateTime.Now.AddDays(-1));
            var st4  = PrettyTime.Format(DateTime.Now.AddDays(-2));
            var st35 = PrettyTime.Format(DateTime.Now.AddHours(-33));

            Console.WriteLine();
        }
Exemplo n.º 5
0
        public void Can_Format_Years(int years, string expected, string cultureName)
        {
            using (var context = new CultureSwitchContext(new CultureInfo(cultureName)))
            {
                var datetime = DateTime.Now;
                var then     = DateTime.Now.AddYears(years);
                var pretty   = new PrettyTime(datetime);

                var result = pretty.Format(then);

                Assert.NotNull(result);
                Assert.AreEqual(expected, result);
            }
        }
Exemplo n.º 6
0
 public static string AsPrettyString(this TimeSpan time)
 {
     return(PrettyTime.Format(time));
 }
Exemplo n.º 7
0
 public static string AsPrettyString(this DateTime date)
 {
     return(PrettyTime.Format(date));
 }
Exemplo n.º 8
0
 public static string ToPrettyTime(this DateTime date)
 {
     var pretty = new PrettyTime();
     return pretty.Format(date);
 }
Exemplo n.º 9
0
        public void Default_Comparison_Compares_To_DateTimeNow()
        {
            var justNow = new PrettyTime().Format(DateTime.Now);

            Assert.AreEqual("moments from now", justNow);
        }
Exemplo n.º 10
0
        public static string ToPrettyTime(this DateTime date)
        {
            var pretty = new PrettyTime();

            return(pretty.Format(date));
        }
Exemplo n.º 11
0
        private async Task selectModpack(Modpack modpack)
        {
            // Timestamp Format: yyyy-MM-dd'T'HH:mm:ss.fff'Z'

            // Browser first, because it takes the longest
            browser.LoadHtml("<style>" + Memory.markdownStyle + "</style>" + CommonMarkConverter.Convert(modpack.Description));

            pnlInstalledVersion.Visible = false;

            pnlDetails.Visible       = true;
            lblName.Text             = modpack.Name;
            lblCreator.Text          = modpack.Creator;
            lblLastChanged.Text      = DateTime.Parse(modpack.LastChanged).ToString("MM'/'dd'/'yyyy");
            lblLastPlayed.Text       = "Never";
            lblMinecraftVersion.Text = modpack.McVersion;
            //rtbDescription.Text = modpack.Description;

            llblSourceFile.Text = Path.GetFileName(modpack.ModpackDownload).truncateString(100, "...");
            llblSourceFile.Tag  = modpack.ModpackDownload;

            lblModpackVersion.Text = modpack.Version;

            if (Memory.forgeSources.ContainsKey(modpack.McVersion))
            {
                llblForgeSource.Text = Path.GetFileName(Memory.forgeSources[modpack.McVersion][0]).truncateString(50, "...");
                llblForgeSource.Tag  = Memory.forgeSources[modpack.McVersion][0];
            }
            else
            {
                llblForgeSource.Text = "N/A";
                llblForgeSource.Tag  = null;
            }

            btnInstallMopack.Width = pnlInstall.Width - 6;
            btnUpdate.Visible      = false;
            btnUninstall.Visible   = false;
            btnUninstall.Tag       = modpack;
            btnInstallMopack.Tag   = modpack;
            btnUpdate.Tag          = modpack;



            this.Text = "Matix's Mod Installer - " + modpack.Name + " (" + modpack.McVersion + ") by " + modpack.Creator;

            string profileLocation = Path.Combine(Memory.minecraftLocation, "launcher_profiles.json");
            string profileString   = "";

            using (StreamReader r = new StreamReader(profileLocation))
            {
                profileString = await r.ReadToEndAsync();
            }


            try
            {
                if (installing == true && installingUID == modpack.UID)
                {
                    pnlInstall.Height          = 103;
                    pgbInstallProgress.Visible = true;
                    lblInstallStatus.Visible   = true;
                    btnInstallMopack.Text      = "Installing...";
                    btnInstallMopack.Enabled   = false;
                }
                else
                {
                    pnlInstall.Height          = 56;
                    pgbInstallProgress.Visible = false;
                    lblInstallStatus.Visible   = false;


                    string modpackDirectory = Path.Combine(Memory.modpacksLocation, Utils.convertIllegalPath(modpack.UID));
                    if (Directory.Exists(modpackDirectory))
                    {
                        btnInstallMopack.Text = "Start Minecraft";
                        if (Memory.launcherFound)
                        {
                            btnInstallMopack.Enabled = true;
                        }
                        else
                        {
                            btnInstallMopack.Enabled = false;
                        }

                        btnUninstall.Visible = true;

                        if (File.Exists(Path.Combine(modpackDirectory, "mmi_mpi.json")))
                        {
                            using (StreamReader r = new StreamReader(Path.Combine(modpackDirectory, "mmi_mpi.json")))
                            {
                                ModpackInfo modpackInfo = JsonConvert.DeserializeObject <ModpackInfo>(await r.ReadToEndAsync());
                                lblForgeInstallation.Text = modpackInfo.VersionId;

                                lblInstalledVersion.Text    = modpackInfo.Version;
                                pnlInstalledVersion.Visible = true;

                                if (modpackInfo.Version != modpack.Version)
                                {
                                    btnInstallMopack.Width = pnlInstall.Width - btnUpdate.Width - btnUninstall.Width - 29;
                                    btnUpdate.Visible      = true;
                                }
                                else
                                {
                                    btnInstallMopack.Width = pnlInstall.Width - btnUninstall.Width - 16;
                                    btnUpdate.Visible      = false;
                                }
                            }
                        }
                        else
                        {
                            _log.Warn("Local Modpack Information is missing.");
                            MessageBox.Show("Seems like some of the local Modpack informations are missing. Updating the Modpack to fix this issue.", "Information Missing", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            await installModpack(modpack);

                            return;
                        }


                        try
                        {
                            dynamic  profiles   = JsonConvert.DeserializeObject(profileString);
                            DateTime lastPlayed = profiles.profiles[modpack.UID].lastUsed;
                            lblLastPlayed.Text = PrettyTime.GetPrettyElapsedTime(lastPlayed);
                        } catch (Exception e)
                        {
                            _log.Info("Launcher profiles not containing selected modpack (\"" + modpack.UID + "\")");
                            _log.Debug(e);
                        }
                    }
                    else
                    {
                        if (installing == false)
                        {
                            btnInstallMopack.Text    = "Download and Install";
                            btnInstallMopack.Width   = pnlInstall.Width - 6;
                            btnInstallMopack.Enabled = true;
                        }
                        else
                        {
                            if (installingUID != modpack.UID)
                            {
                                btnInstallMopack.Text    = "Installing other Modpack";
                                btnInstallMopack.Enabled = false;
                            }
                        }
                    }
                }


                pcbIcon.Image = Properties.Resources.loading;
                if (Utils.validateURL(modpack.Icon))
                {
                    pcbIcon.Image = await Utils.loadBitmapFromUrl(modpack.Icon);
                }
                else
                {
                    pcbIcon.Image = Utils.emptyBitmap();
                }
            } catch (Exception e)
            {
                _log.Error("Error: Could not load Modpack details.");
                if (Directory.Exists(Path.Combine(Memory.modpacksLocation, Utils.convertIllegalPath(modpack.UID))))
                {
                    _log.Info(e, "Error: Uninstalling Modpack to fix bug.");
                    DialogResult uninstall = MessageBox.Show("Could not load Modpack details. Should the Modpack be uninstalled to fix this issue?", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    if (uninstall == DialogResult.OK)
                    {
                        await uninstallModpack(modpack);

                        return;
                    }
                    else
                    {
                        pnlDetails.Visible = false;
                    }
                }
            }

            modsTable = Utils.createDataTable(modpack.Mods);

            modsTable.Columns.Add("WebsiteShort");
            modsTable.Columns.Add("WebsiteShortArea", typeof(LinkArea));

            foreach (DataRow row in modsTable.Rows)
            {
                row.SetField("WebsiteShort", row.Field <string>("Website").truncateString(50, "..."));
                LinkArea linkArea = new LinkArea(0, row.Field <string>("Website").truncateString(50, "...").Length);
                row.SetField("WebsiteShortArea", linkArea);
            }

            modName.DataBindings.Clear();
            modWebsite.DataBindings.Clear();
            modVersion.DataBindings.Clear();

            modName.DataBindings.Add("Text", modsTable, "Name");
            modVersion.DataBindings.Add("Text", modsTable, "Version");
            modWebsite.DataBindings.Add("Text", modsTable, "WebsiteShort");
            modWebsite.DataBindings.Add("Tag", modsTable, "Website");
            modWebsite.DataBindings.Add("LinkArea", modsTable, "WebsiteShortArea");

            drMods.DataSource = modsTable;
        }