Exemple #1
0
        public static void XamlsAreEqualStringTest()
        {
            var xml1 = File.ReadAllText(Path.Combine(PlayniteTests.ResourcesPath, "XmlTest", "Xml1.xaml"));
            var xml2 = File.ReadAllText(Path.Combine(PlayniteTests.ResourcesPath, "XmlTest", "Xml2.xaml"));
            var xml3 = File.ReadAllText(Path.Combine(PlayniteTests.ResourcesPath, "XmlTest", "Xml3.xaml"));
            var xml4 = File.ReadAllText(Path.Combine(PlayniteTests.ResourcesPath, "XmlTest", "Xml4.xaml"));

            Assert.IsTrue(Xml.AreEqual(xml1, xml2));
            Assert.IsFalse(Xml.AreEqual(xml1, xml3));
            Assert.IsFalse(Xml.AreEqual(xml1, xml4));
        }
Exemple #2
0
 public static void AreEqualStringTest()
 {
     Assert.IsTrue(Xml.AreEqual(
                       @"<t><a att='aa' ett='bb'>11</a></t>",
                       @"<t><a att='aa' ett='bb'>11</a></t>"));
     Assert.IsTrue(Xml.AreEqual(
                       @"<t><a att='aa' ett='bb'>11</a></t>",
                       @"<t><a ett='bb' att='aa'>11</a></t>"));
     Assert.IsTrue(Xml.AreEqual(
                       @"<t><a att='aa'    ett='bb'>11</a>  </t>",
                       @"<t>  <a ett='bb' att='aa'>11</a></t>"));
 }
Exemple #3
0
        public static bool AreFilesEqual(string file1, string file2)
        {
            var file1Info = new FileInfo(file1);
            var file2Info = new FileInfo(file2);

            if (file1Info.Length != file2Info.Length)
            {
                return(false);
            }

            if (file1Info.Extension.Equals(".xaml", StringComparison.OrdinalIgnoreCase))
            {
                return(Xml.AreEqual(File.ReadAllText(file1), File.ReadAllText(file2)));
            }
            else
            {
                return(FileSystem.GetMD5(file1) == FileSystem.GetMD5(file2));
            }
        }
Exemple #4
0
        public static void SimpleAreEqualStringTest()
        {
            Assert.IsTrue(Xml.AreEqual(
                              @"<t><a att='aa'  ett='bb'>11</a></t>",
                              @"<t><a att='aa' ett='bb'>11</a></t>"));
            Assert.IsTrue(Xml.AreEqual(
                              @"<t><a att='aa' ett='bb'>11</a></t>",
                              @"<t><a ett='bb' att='aa'>11</a></t>"));
            Assert.IsTrue(Xml.AreEqual(
                              @"<t><a att='aa'    ett='bb'>11</a>  </t>",
                              @"<t>  <a ett='bb' att='aa'>11</a></t>"));

            Assert.IsFalse(Xml.AreEqual(
                               @"<t><a att='aa' ett='bb'>11</a></t>",
                               @"<t><a att='aa' ett='bb'>22</a></t>"));
            Assert.IsFalse(Xml.AreEqual(
                               @"<t><a att='aa' ett='aa'>11</a></t>",
                               @"<t><a ett='bb' att='aa'>11</a></t>"));
            Assert.IsFalse(Xml.AreEqual(
                               @"<t><a att='aa'    ett='bb'>11</a>  </t>",
                               @"<t>  <b ett='bb' att='aa'>11</b></t>"));
        }
Exemple #5
0
        public static void UpdateTheme(string themeDirectory, ApplicationMode mode)
        {
            var themeManifestPath   = Path.Combine(themeDirectory, "theme.yaml");
            var currentThemeMan     = ThemeDescription.FromFile(themeManifestPath);
            var origThemeApiVersion = new Version(currentThemeMan.ThemeApiVersion);

            if (!File.Exists(Path.Combine(themeDirectory, Themes.ThemeProjName)))
            {
                throw new Exception("Cannot update theme that was not generated via Toolbox utility.");
            }

            if (ThemeManager.GetApiVersion(mode) == origThemeApiVersion)
            {
                logger.Warn("Theme is already updated to current API version.");
                return;
            }

            var folder = Paths.GetNextBackupFolder(themeDirectory);

            BackupTheme(themeDirectory, Paths.GetNextBackupFolder(themeDirectory));
            logger.Info($"Current theme backed up into \"{Path.GetFileName(folder)}\" folder.");

            var defaultThemeDir = Path.Combine(Paths.GetThemesPath(mode), "Default");
            var origFilesZip    = Path.Combine(Paths.ChangeLogsDir, currentThemeMan.ThemeApiVersion + ".zip");
            var themeChanges    = Themes.GetThemeChangelog(origThemeApiVersion, mode);

            if (!themeChanges.HasItems())
            {
                logger.Info("No files to update.");
                return;
            }

            // Update files
            var notUpdated = new List <string>();

            using (var origFiles = ZipFile.OpenRead(origFilesZip))
            {
                foreach (var changedFile in themeChanges)
                {
                    var subpath      = Common.Paths.FixSeparators(Regex.Replace(changedFile.Path, ".+Themes/(Desktop|Fullscreen)/Default/", ""));
                    var curThemePath = Path.Combine(themeDirectory, subpath);
                    var defaultPath  = Path.Combine(defaultThemeDir, subpath);
                    if (changedFile.ChangeType == "D")
                    {
                        FileSystem.DeleteFile(curThemePath);
                    }
                    else
                    {
                        var canUpdate = false;
                        if (File.Exists(curThemePath))
                        {
                            var origEntry = origFiles.GetEntry(ThemeManager.GetThemeRootDir(mode) + "\\" + subpath);
                            if (origEntry == null)
                            {
                                canUpdate = false;
                            }
                            else
                            {
                                var origContent = string.Empty;
                                using (var reader = new StreamReader(origEntry.Open()))
                                {
                                    origContent = reader.ReadToEnd();
                                }

                                if (subpath.EndsWith(".xaml", StringComparison.OrdinalIgnoreCase))
                                {
                                    if (Xml.AreEqual(origContent, File.ReadAllText(curThemePath)))
                                    {
                                        canUpdate = true;
                                    }
                                }
                                else
                                {
                                    if (origContent == FileSystem.GetMD5(curThemePath))
                                    {
                                        canUpdate = true;
                                    }
                                }
                            }
                        }
                        else
                        {
                            canUpdate = true;
                        }

                        if (canUpdate)
                        {
                            FileSystem.CopyFile(defaultPath, curThemePath);
                        }
                        else
                        {
                            logger.Debug($"Can't update {subpath}.");
                            notUpdated.Add(subpath);
                        }
                    }
                }
            }

            if (notUpdated.HasItems())
            {
                logger.Warn("Couldn't update some theme files, please update them manually:");
                notUpdated.ForEach(a => logger.Warn(a));
            }

            // Update common files
            GenerateCommonThemeFiles(mode, themeDirectory);

            // Update manifest
            currentThemeMan.ThemeApiVersion = ThemeManager.GetApiVersion(mode).ToString(3);
            File.WriteAllText(themeManifestPath, Serialization.ToYaml(currentThemeMan));
        }