Example #1
0
        public static void ExportAll(string exportDirectory, bool forceRegenerate = true)
        {
            if (!Directory.Exists(exportDirectory))
            {
                Directory.CreateDirectory(exportDirectory);
            }

            string md5File = Path.Combine(ExcelPath, "md5.txt");
            if (!File.Exists(md5File))
            {
                md5Info = new ExcelMD5Info();
            }
            else
            {
                md5Info = JsonHelper.FromJson<ExcelMD5Info>(File.ReadAllText(md5File));
            }

            string[] files = Directory.GetFiles(ExcelPath);
            foreach (string filePath in files)
            {
                if (filePath.Length < 12 || Path.GetFileName(filePath).StartsWith("~") || !filePath.EndsWith("Config.xlsx"))
                {
                    continue;
                }
                string fileName = Path.GetFileName(filePath);
                string oldMD5 = md5Info.Get(fileName);
                string md5 = MD5Helper.FileMD5(filePath);
                md5Info.Add(fileName, md5);
                if (md5 == oldMD5 && !forceRegenerate)
                {
                    continue;
                }

                Export(filePath, exportDirectory);
            }

            File.WriteAllText(md5File, JsonHelper.ToJson(md5Info));
        }
Example #2
0
        private static void GenerateVersionProto(string dir, VersionConfig versionProto, string relativePath)
        {
            foreach (string file in Directory.GetFiles(dir))
            {
                string   md5      = MD5Helper.FileMD5(file);
                FileInfo fi       = new FileInfo(file);
                long     size     = fi.Length;
                string   filePath = relativePath == "" ? fi.Name : $"{relativePath}/{fi.Name}";

                versionProto.FileInfoDict.Add(filePath, new FileVersionInfo
                {
                    File = filePath,
                    MD5  = md5,
                    Size = size,
                });
            }

            foreach (string directory in Directory.GetDirectories(dir))
            {
                DirectoryInfo dinfo = new DirectoryInfo(directory);
                string        rel   = relativePath == "" ? dinfo.Name : $"{relativePath}/{dinfo.Name}";
                GenerateVersionProto($"{dir}/{dinfo.Name}", versionProto, rel);
            }
        }