/// <summary>
    /// 导出所有
    /// </summary>
    /// <param name="exportDir"></param>
    private void ExportAll(string exportDir)
    {
        //md5文件的路径
        string md5File = Path.Combine(ExcelPath, "md5.txt");

        //如果不包含md5文件 构建ExcelMD5Info
        if (!File.Exists(md5File))
        {
            this.md5Info = new ExcelMD5Info();
        }
        else
        {
            //如果包含 就读取文件的所有文本 为json格式
            //再反序列化成实体类ExcelMD5Info
            this.md5Info = MongoHelper.FromJson <ExcelMD5Info>(File.ReadAllText(md5File));
        }
        //遍历"../Excel"路径下的所有文件
        foreach (string filePath in Directory.GetFiles(ExcelPath))
        {
            //如果扩展名不是.xlsx 继续遍历下一个元素
            if (Path.GetExtension(filePath) != ".xlsx")
            {
                continue;
            }
            //临时缓存文件 忽略之
            if (Path.GetFileName(filePath).StartsWith("~"))
            {
                continue;
            }
            //如果是.xlsx文件
            //获取文件名
            string fileName = Path.GetFileName(filePath);
            //旧的md5码
            string oldMD5 = this.md5Info.Get(fileName);
            //当前的md5码
            string md5 = MD5Helper.FileMD5(filePath);
            //缓存起来
            this.md5Info.Add(fileName, md5);
            //对比md5 如果一样 则继续检查下一个元素
            if (md5 == oldMD5)
            {
                continue;
            }
            //如果不一样 则调用Export接口 filePath:文件路径 exportDir导出路径,客户端为clientPath变量的值
            Export(filePath, exportDir);
        }

        //全部遍历完 就将md5Info序列化成json 写入到md5File文件中
        File.WriteAllText(md5File, this.md5Info.ToJson());

        Log.Info("所有表导表完成");
        AssetDatabase.Refresh();
    }
Ejemplo n.º 2
0
    private void ExportAll(string exportDir)
    {
        string md5File = Path.Combine(ExcelPath, "md5.txt");
        if (!File.Exists(md5File))
        {
            this.md5Info = new ExcelMD5Info();
        }
        else
        {
            this.md5Info = MongoHelper.FromJson<ExcelMD5Info>(File.ReadAllText(md5File));
        }
        string[] files = Directory.GetFiles(ExcelPath);

        foreach (string filePath in files)
        {
            if (Path.GetExtension(filePath) != ".xlsx")
            {
                continue;
            }
            if (Path.GetFileName(filePath).StartsWith("~"))
            {
                continue;
            }
            if (!Path.GetFileNameWithoutExtension(filePath).Contains("Config"))
            {
                continue;
            }
            string fileName = Path.GetFileName(filePath);
            string oldMD5 = this.md5Info.Get(fileName);
            string md5 = MD5Helper.FileMD5(filePath);
            this.md5Info.Add(fileName, md5);
            //if (md5 == oldMD5)
            //{
            //    continue;
            //}

            Export(filePath, exportDir);
        }

        File.WriteAllText(md5File, this.md5Info.ToJson());

        Log.Info("所有表导表完成");
        AssetDatabase.Refresh();
    }
    private static void ExportAll(string exportDir)
    {
        string md5File = Path.Combine(ExcelPath, "md5.txt");

        if (!File.Exists(md5File))
        {
            md5Info = new ExcelMD5Info();
        }
        else
        {
            md5Info = MongoHelper.FromJson <ExcelMD5Info>(File.ReadAllText(md5File));
        }

        foreach (string filePath in Directory.GetFiles(ExcelPath))
        {
            if (Path.GetExtension(filePath) != ".xlsx")
            {
                continue;
            }

            if (Path.GetFileName(filePath).StartsWith("~"))
            {
                continue;
            }

            string fileName = Path.GetFileName(filePath);
            string oldMD5   = md5Info.Get(fileName);
            string md5      = MD5Helper.FileMD5(filePath);
            md5Info.Add(fileName, md5);


            Export(filePath, exportDir);
        }

        File.WriteAllText(md5File, md5Info.ToJson());

        Log.Info("所有表导表完成");
        AssetDatabase.Refresh();
    }
Ejemplo n.º 4
0
    private void ExportAll()
    {
        string md5File = Path.Combine(ExcelPath, "md5.txt");

        if (!File.Exists(md5File))
        {
            this.md5Info = new ExcelMD5Info();
        }
        else
        {
            this.md5Info = MongoHelper.FromJson <ExcelMD5Info>(File.ReadAllText(md5File));
        }

        string[] tempArr = Directory.GetFiles(ExcelPath, "*.xlsx", SearchOption.AllDirectories);


        foreach (string filePath in tempArr)
        {
            if (Path.GetExtension(filePath) != ".xlsx")
            {
                continue;
            }
            if (Path.GetFileName(filePath).StartsWith("~"))
            {
                continue;
            }

            string eliminatePath = "";
            string exportDir     = "";
            switch (_excelType)
            {
            case ExcelType.Client:
                if (filePath.Contains(_publicExcelPartPath))
                {
                    exportDir = _publicExportPath;
                }
                else
                {
                    exportDir = _clientExportPath;
                }
                eliminatePath = _serverExcelPartPath;
                break;

            case ExcelType.Public:
                break;

            case ExcelType.Server:
                if (filePath.Contains(_publicExcelPartPath))
                {
                    exportDir = _publicExportPath;
                }
                else
                {
                    exportDir = _serverExportPath;
                }
                eliminatePath = _clientExcelPartPath;
                break;
            }
            if (filePath.Contains(eliminatePath))
            {
                continue;
            }

            string fileName = Path.GetFileName(filePath);
            string oldMD5   = this.md5Info.Get(fileName);
            string md5Key   = _excelType + "-" + fileName;
            string md5      = MD5Helper.FileMD5(filePath);
            this.md5Info.Add(md5Key, md5);
            if (md5 == oldMD5)
            {
                continue;
            }

            Export(filePath, exportDir);

            if (_excelType == ExcelType.Client)
            {
                string protoName  = Path.GetFileNameWithoutExtension(fileName);
                string sourcePath = Path.Combine(exportDir, $"{protoName}.txt");
                string destPath   = Path.Combine(_clientCopyPath, $"{protoName}.txt");
                if (File.Exists(destPath))
                {
                    File.Delete(destPath);
                }
                File.Copy(sourcePath, destPath);
            }

            else if (_excelType == ExcelType.Server)
            {
                string protoName  = Path.GetFileNameWithoutExtension(fileName);
                string sourcePath = Path.Combine(exportDir, $"{protoName}.txt");
                string destPath   = Path.Combine(_serverCopyPath, $"{protoName}.txt");
                if (File.Exists(destPath))
                {
                    File.Delete(destPath);
                }
                File.Copy(sourcePath, destPath);
            }
        }

        File.WriteAllText(md5File, this.md5Info.ToJson());

        Log.Info("所有表导表完成");
        AssetDatabase.Refresh();
    }