示例#1
0
文件: Program.cs 项目: khRiku/Tools
        /// <summary>
        /// 替换原本文件
        /// </summary>
        private static void Replace()
        {
            Console.WriteLine("开始替换文件 ... ... ");
            {
                string tDataPath = mCurDiretory + "\\" + mAllFileName;
                string tData     = File.ReadAllText(tDataPath);
                if (string.IsNullOrEmpty(tData))
                {
                    Console.WriteLine("错误:读取内容为空, 请确保该文件是否存在 路径 = " + tDataPath);
                    Console.WriteLine("恢复失败");
                    return;
                }

                AllFileData tAllFileData     = JsonMapper.ToObject <AllFileData>(tData);
                string      tStartFolderPath = mCurDiretory;

                for (int i = 0; i < tAllFileData.mOneFileDataList.Count; ++i)
                {
                    OneFileData tOneFileData = tAllFileData.mOneFileDataList[i];

                    string tSavePath = tStartFolderPath + "\\" + tOneFileData.mRelativePath;

                    int    tLastSperatIndex = tSavePath.LastIndexOf(@"\");
                    string tFolderPath      = tSavePath.Remove(tLastSperatIndex, tSavePath.Length - tLastSperatIndex);
                    if (Directory.Exists(tFolderPath) == false)
                    {
                        Directory.CreateDirectory(tFolderPath);
                    }

                    File.WriteAllText(tSavePath, tOneFileData.mContent, Encoding.GetEncoding("gb2312"));
                }
            }
            Console.WriteLine("文件替换结束 ");
        }
示例#2
0
文件: Program.cs 项目: khRiku/Tools
        /// <summary>
        /// 将所有内容转换为一个文件
        /// </summary>
        private static void TransformToOneFile()
        {
            AllFileData tAllFileData = new AllFileData();

            tAllFileData.mStartPath = mCurDiretory;

            Console.WriteLine("格式转换开始 ... ... ");
            {
                DirectoryInfo tDierectInfo = new DirectoryInfo(mCurDiretory);
                FileInfo[]    tFileInfoArr = tDierectInfo.GetFiles("*", SearchOption.AllDirectories);
                for (int i = 0; i < tFileInfoArr.Length; ++i)
                {
                    FileInfo tFileInfo = tFileInfoArr[i];
                    if (mProcessExtension.Contains(tFileInfo.Extension) == false)
                    {
                        continue;
                    }

                    OneFileData tOneFileData = new OneFileData();
                    tOneFileData.mRelativePath = tFileInfo.FullName.Replace(mCurDiretory, "");
                    tOneFileData.mContent      = File.ReadAllText(tFileInfo.FullName, Encoding.GetEncoding("gb2312"));

                    tAllFileData.mOneFileDataList.Add(tOneFileData);
                }
            }

            File.WriteAllText(mCurDiretory + "\\" + mAllFileName, JsonMapper.ToJson(tAllFileData), Encoding.GetEncoding("gb2312"));
            Console.WriteLine("格式转换成功结束 ");
        }