Exemple #1
0
        private void compileOfflineData()
        {
            var onlineRoot = $"https://raw.githubusercontent.com/{config.Owner}/Bilibili-Evolved/master/";
            // var urlList = (from match in new Regex(@"path:\s*""(.*)""").Matches(offlineText)
            //                as IEnumerable<Match>
            //                select "min/" + match.Groups[1].Value.Trim()
            //               ).ToList();
            // var urlList = from file in Directory.GetFiles("min")
            //               where !file.Contains("dark-slice") && !Path.GetFileName(file).StartsWith("bundle.")
            //               select file.Replace(@"\", "/");

            var downloadCodeStart = @"// \+#Offline build placeholder";
            var downloadCodeEnd   = @"// \-#Offline build placeholder";
            var downloadCodes     = new Regex($"({downloadCodeStart}([^\0]*){downloadCodeEnd})").Match(offlineText).Groups[0].Value;

            var offlineData = "const offlineData = {};" + Environment.NewLine;

            foreach (var(url, text) in CachedMinFiles.OrderBy(p => p.Key))
            {
                if (url.EndsWith(".js"))
                {
                    offlineData = offlineData + $"offlineData[\"{onlineRoot + url}\"] = {text}" + Environment.NewLine;
                }
                else
                {
                    offlineData = offlineData + $"offlineData[\"{onlineRoot + url}\"] = `{text.Replace("\\", "\\\\")}`;" + Environment.NewLine;
                }
            }
            offlineText = offlineText
                          .Replace(@"// [Offline build placeholder]", offlineData)
                          .Replace(downloadCodes, "this.text=this.type.preprocessor(offlineData[this.url]);resolve(this.text);");
        }
Exemple #2
0
 public ProjectBuilder BuildBundle()
 {
     if (changedBundleFiles.Any())
     {
         // var urlList = from file in Directory.GetFiles("min")
         //               where !file.Contains("dark-slice") && !Path.GetFileName(file).StartsWith("bundle.")
         //               select file.Replace(@"\", "/");
         var hashDict = new Dictionary <string, string>();
         var zipName  = "min/bundle.zip";
         if (File.Exists(zipName))
         {
             File.Delete(zipName);
         }
         using (var sha256 = new SHA256Managed())
             using (var zip = ZipFile.Open(zipName, ZipArchiveMode.Update))
             {
                 foreach (var(url, text) in CachedMinFiles.OrderBy(p => p.Key))
                 {
                     var filename = Path.GetFileName(url);
                     var hash     = string.Join("", sha256.ComputeHash(Encoding.UTF8.GetBytes(text)).Select(b => b.ToString("X2")).ToArray());
                     zip.CreateEntryFromFile(url, filename, CompressionLevel.NoCompression);
                     hashDict.Add(filename, hash);
                 }
             }
         File.WriteAllText("min/bundle.json", JsonConvert.SerializeObject(hashDict, Formatting.Indented));
         WriteSuccess("Bundle build complete.");
     }
     else
     {
         WriteSuccess("Skipped bundle build.");
     }
     return(this);
 }
        private string compileOnlineData()
        {
            var onlineRoot = $"https://raw.githubusercontent.com/{config.Owner}/Bilibili-Evolved/preview/";
            // var urlList = from file in Directory.GetFiles("min")
            //               where !file.Contains("dark-slice") && !Path.GetFileName(file).StartsWith("bundle.")
            //               select file.Replace(@"\", "/");
            var onlineData = "const onlineData = {};" + Environment.NewLine;

            foreach (var(url, text) in CachedMinFiles.OrderBy(p => p.Key))
            {
                if (url.EndsWith(".js"))
                {
                    onlineData = onlineData + $"onlineData[\"{onlineRoot + url}\"] = {text}" + Environment.NewLine;
                }
                else
                {
                    onlineData = onlineData + $"onlineData[\"{onlineRoot + url}\"] = `{text.Replace("\\", "\\\\")}`;" + Environment.NewLine;
                }
            }
            return(onlineData);
        }