private void setReadmeHTML(string name, ref HmodReadme hReadme)
        {
            Color  color = this.BackColor;
            string html  = String.Format(Properties.Resources.readmeTemplateHTML, Properties.Resources.readmeTemplateCSS, name, formatReadme(ref Readme), $"rgb({color.R},{color.G},{color.B})");

            wbReadme.DocumentText = html;
        }
Exemple #2
0
        public void clear()
        {
            Readme = new HmodReadme("");

            tbReadme.Text = string.Empty;
            return;
        }
        public void clear()
        {
            Readme = new HmodReadme("");
            Color  color = this.BackColor;
            string html  = String.Format(Properties.Resources.readmeTemplateHTML, Properties.Resources.readmeTemplateCSS, "", "", $"rgb({color.R},{color.G},{color.B})");

            wbReadme.DocumentText = html;
        }
Exemple #4
0
 public Item(string filename, string readme = null, bool markdownReadme = false)
 {
     FileName       = filename;
     Kind           = ItemKindFromFilename(FileName);
     Name           = RawName;
     Category       = null;
     Creator        = null;
     Version        = null;
     EmulatedSystem = null;
     URL            = null;
     MD5            = null;
     SHA1           = null;
     Extract        = false;
     Readme         = new HmodReadme(readme ?? "", markdownReadme);
     setValues();
 }
 public void setReadme(string name, HmodReadme hReadme)
 {
     Readme = hReadme;
     setReadmeHTML(name, ref Readme);
 }
 private string formatReadme(ref HmodReadme hReadme)
 {
     return(CommonMarkConverter.Convert(String.Join("  \n", hReadme.headingLines) + "\n\n" + (hReadme.isMarkdown || hReadme.readme.Length == 0 ? hReadme.readme : $"```\n{hReadme.readme}\n```")));
 }
Exemple #7
0
        public Hmod(string mod, string[] installedHmods = null)
        {
            isInstalled = false;
            if (installedHmods != null)
            {
                isInstalled = installedHmods.Contains(mod);
            }
            RawName       = mod;
            this.HmodPath = null;
            this.isFile   = false;

            string usermodsDirectory = Path.Combine(Program.BaseDirectoryExternal, "user_mods");
            string cacheDir          = Shared.PathCombine(Program.BaseDirectoryExternal, "cache", "readme_cache");
            string cacheFile         = Path.Combine(cacheDir, $"{mod}.xml");


            Dictionary <string, string> readmeData   = new Dictionary <string, string>();
            Dictionary <string, string> libretroInfo = new Dictionary <string, string>();

            LastModified      = DateTime.UtcNow;
            this.LibretroInfo = new Dictionary <string, string>();

            try
            {
                var dir = Path.Combine(usermodsDirectory, mod + ".hmod");
                if (Directory.Exists(dir))
                {
                    var files = (from f in (new DirectoryInfo(dir)).GetFiles("*", SearchOption.AllDirectories)
                                 orderby f.LastWriteTimeUtc descending
                                 select f.LastWriteTimeUtc);

                    if (files.Count() > 0)
                    {
                        LastModified = files.First();
                    }

                    isFile   = false;
                    HmodPath = dir;
                    foreach (var f in HmodReadme.readmeFiles)
                    {
                        var fn = Path.Combine(dir, f);
                        if (File.Exists(fn))
                        {
                            readmeData.Add(f.ToLower(), File.ReadAllText(fn));
                        }
                    }

                    foreach (string file in Directory.EnumerateFiles(dir, "*_libretro.info"))
                    {
                        libretroInfo.Add(file, File.ReadAllText(file));
                    }
                    this.LibretroInfo = libretroInfo;
                }
                else if (File.Exists(dir))
                {
                    LastModified = new FileInfo(dir).LastWriteTimeUtc;
                    isFile       = true;
                    HmodPath     = dir;

                    MetadataCache cache;
                    FileInfo      info = new FileInfo(dir);

                    bool skipExtraction = false;
                    if (File.Exists(cacheFile))
                    {
                        try
                        {
                            cache = MetadataCache.Deserialize(cacheFile);
                            if (cache.LastModified == info.LastWriteTimeUtc)
                            {
                                skipExtraction = true;
                                readmeData     = cache.getReadmeDictionary();
                                foreach (string[] infoFile in cache.LibretroInfo)
                                {
                                    this.LibretroInfo.Add(infoFile[0], infoFile[1]);
                                }
                            }
                        }
                        catch { }
                    }


                    if (!skipExtraction)
                    {
                        using (var reader = ReaderFactory.Open(File.OpenRead(dir)))
                        {
                            while (reader.MoveToNextEntry())
                            {
                                foreach (var readmeFilename in HmodReadme.readmeFiles)
                                {
                                    if (reader.Entry.Key.ToLower() != readmeFilename && reader.Entry.Key.ToLower() != $"./{readmeFilename}")
                                    {
                                        continue;
                                    }

                                    using (var o = new MemoryStream())
                                        using (var e = reader.OpenEntryStream())
                                        {
                                            e.CopyTo(o);
                                            readmeData.Add(readmeFilename, Encoding.UTF8.GetString(o.ToArray()));
                                        }
                                }

                                if (reader.Entry.Key.ToLower().EndsWith("_libretro.info"))
                                {
                                    using (var o = new MemoryStream())
                                        using (var e = reader.OpenEntryStream())
                                        {
                                            e.CopyTo(o);
                                            libretroInfo.Add(reader.Entry.Key, Encoding.UTF8.GetString(o.ToArray()));
                                        }
                                }
                            }
                        }
                        cache = new MetadataCache(readmeData, libretroInfo, "", info.LastWriteTimeUtc);

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

                        this.LibretroInfo = libretroInfo;

                        File.WriteAllText(cacheFile, cache.Serialize());
                    }
                }
                else
                {
                    if (File.Exists(cacheFile))
                    {
                        try
                        {
                            MetadataCache cache;
                            cache      = MetadataCache.Deserialize(cacheFile);
                            readmeData = cache.getReadmeDictionary();
                        }
                        catch { }
                    }
                }
            }
            catch (Exception e)
            {
            }

            string readme;
            bool   markdown = false;

            if (readmeData.TryGetValue("readme.md", out readme))
            {
                markdown = true;
            }
            else if (readmeData.TryGetValue("readme.txt", out readme))
            {
            }
            else if (readmeData.TryGetValue("readme", out readme))
            {
            }
            else
            {
                readme = "";
            }

            this.Readme = new HmodReadme(readme, markdown);

            if (!this.Readme.frontMatter.TryGetValue("Name", out this.Name))
            {
                this.Name = mod;
            }
            if (!this.Readme.frontMatter.TryGetValue("Category", out this.Category))
            {
                this.Category = Properties.Resources.Unknown;
            }

            if (!this.Readme.frontMatter.TryGetValue("Version", out this.Version))
            {
                this.Version = null;
            }

            if (!this.Readme.frontMatter.TryGetValue("Creator", out this.Creator))
            {
                this.Creator = Properties.Resources.Unknown;
            }

            if (!this.Readme.frontMatter.TryGetValue("Emulated System", out this.EmulatedSystem))
            {
                this.EmulatedSystem = Properties.Resources.Unknown;
            }
        }
        private string formatReadme(string name, ref HmodReadme hReadme)
        {
            string markdownTitle = (name != null && name.Trim() != "" ? $"# {name}\n\n" : "");

            return(CommonMarkConverter.Convert(markdownTitle + String.Join("  \n", hReadme.headingLines) + "\n\n" + (hReadme.isMarkdown || hReadme.readme.Length == 0 ? hReadme.readme : $"```\n{hReadme.readme}\n```")));
        }
Exemple #9
0
 public void setReadme(string readme, bool markdown = false)
 {
     Readme = new HmodReadme(readme, markdown);
     setValues();
 }
Exemple #10
0
 private void setReadmeHTML(string name, ref HmodReadme hReadme)
 {
     tbReadme.Text = hReadme.rawReadme.Replace("\r", "").Replace("\n", "\r\n").Trim();
     return;
 }
Exemple #11
0
        public Hmod(string mod, string[] installedHmods = null)
        {
            isInstalled = false;
            if (installedHmods != null)
            {
                isInstalled = installedHmods.Contains(mod);
            }
            RawName       = mod;
            this.HmodPath = null;
            this.isFile   = false;

            string usermodsDirectory = Path.Combine(Program.BaseDirectoryExternal, "user_mods");
            string cacheDir          = Shared.PathCombine(Program.BaseDirectoryExternal, "user_mods", "readme_cache");
            string cacheFile         = Path.Combine(cacheDir, $"{mod}.xml");


            Dictionary <string, string> readmeData = new Dictionary <string, string>();

            try
            {
                var dir = Path.Combine(usermodsDirectory, mod + ".hmod");
                if (Directory.Exists(dir))
                {
                    isFile   = false;
                    HmodPath = dir;
                    foreach (var f in HmodReadme.readmeFiles)
                    {
                        var fn = Path.Combine(dir, f);
                        if (File.Exists(fn))
                        {
                            readmeData.Add(f.ToLower(), File.ReadAllText(fn));
                        }
                    }
                }
                else if (File.Exists(dir))
                {
                    isFile   = true;
                    HmodPath = dir;

                    ReadmeCache cache;
                    FileInfo    info = new FileInfo(dir);

                    bool skipExtraction = false;
                    if (File.Exists(cacheFile))
                    {
                        try
                        {
                            cache = XMLSerialization.DeserializeXMLFileToObject <ReadmeCache>(cacheFile);
                            if (cache.LastModified == info.LastWriteTimeUtc)
                            {
                                skipExtraction = true;
                                readmeData     = cache.getReadmeDictionary();
                            }
                        }
                        catch { }
                    }


                    if (!skipExtraction)
                    {
                        using (var reader = ReaderFactory.Open(File.OpenRead(dir)))
                        {
                            while (reader.MoveToNextEntry())
                            {
                                foreach (var readmeFilename in HmodReadme.readmeFiles)
                                {
                                    if (reader.Entry.Key.ToLower() != readmeFilename && reader.Entry.Key.ToLower() != $"./{readmeFilename}")
                                    {
                                        continue;
                                    }

                                    var o = new MemoryStream();
                                    reader.OpenEntryStream().CopyTo(o);
                                    readmeData.Add(readmeFilename, Encoding.UTF8.GetString(o.ToArray()));
                                }
                            }
                        }
                        cache = new ReadmeCache(readmeData, "", info.LastWriteTimeUtc);

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

                        File.WriteAllText(cacheFile, cache.Serialize());
                    }
                }
                else
                {
                    if (File.Exists(cacheFile))
                    {
                        try
                        {
                            ReadmeCache cache;
                            cache      = XMLSerialization.DeserializeXMLFileToObject <ReadmeCache>(cacheFile);
                            readmeData = cache.getReadmeDictionary();
                        }
                        catch { }
                    }
                }
            }
            catch
            {
            }

            string readme;
            bool   markdown = false;

            if (readmeData.TryGetValue("readme.md", out readme))
            {
                markdown = true;
            }
            else if (readmeData.TryGetValue("readme.txt", out readme))
            {
            }
            else if (readmeData.TryGetValue("readme", out readme))
            {
            }
            else
            {
                readme = "";
            }

            this.Readme = new HmodReadme(readme, markdown);

            if (!this.Readme.frontMatter.TryGetValue("Name", out this.Name))
            {
                this.Name = mod;
            }
            if (!this.Readme.frontMatter.TryGetValue("Category", out this.Category))
            {
                this.Category = Properties.Resources.Unknown;
            }

            if (!this.Readme.frontMatter.TryGetValue("Version", out this.Version))
            {
                this.Version = null;
            }

            if (!this.Readme.frontMatter.TryGetValue("Creator", out this.Creator))
            {
                this.Creator = Properties.Resources.Unknown;
            }

            if (!this.Readme.frontMatter.TryGetValue("Emulated System", out this.EmulatedSystem))
            {
                this.EmulatedSystem = Properties.Resources.Unknown;
            }
        }
Exemple #12
0
 public void setReadme(string name, HmodReadme hReadme)
 {
     readmeControl.setReadme(name, hReadme);
 }