コード例 #1
0
    /// <summary>
    /// A1 can be null, then will be joined default like D:\_Test\AllProjectsSearch\AllProjectsSearch\ by DefaultFolderPath()
    /// A2 can be slashed or backslashed. Will be appended to A1.
    /// To A2 will be add _Original automatically
    /// A3 is append after folder and folderFrom (with _Original\). can be null or SE
    ///
    /// A5 whether replace _Original in non original Folder
    /// </summary>
    /// <param name="appName"></param>
    /// <param name="featureOrType"></param>
    public static List <string> RefreshOriginalFiles(string baseFolder, object featureOrType, string modeOfFeature, bool copyFilesRecursively, bool replace_Original)
    {
        if (baseFolder == null)
        {
            baseFolder = DefaultFolderPath();
        }

        string feature = NameOfFeature(featureOrType);

        FS.WithoutEndSlash(ref baseFolder);
        baseFolder = baseFolder + "\\" + feature;
        var    folderFrom = baseFolder + "_Original\\";
        string folder     = baseFolder + "\\";

        if (!string.IsNullOrEmpty(modeOfFeature))
        {
            modeOfFeature = modeOfFeature.TrimEnd('\\') + "\\";
            folderFrom   += modeOfFeature;
            folder       += modeOfFeature;
        }

        FS.GetFiles(folder, copyFilesRecursively).ToList().ForEach(d => FS.TryDeleteFile(d));
        if (copyFilesRecursively)
        {
            FS.CopyAllFilesRecursively(folderFrom, folder, FileMoveCollisionOption.Overwrite);
        }
        else
        {
            FS.CopyAllFiles(folderFrom, folder, FileMoveCollisionOption.Overwrite);
        }

        var files = FS.GetFiles(folder);

        if (replace_Original)
        {
            const string _Original = "_Original";

            for (int i = 0; i < files.Count; i++)
            {
                var item  = files[i];
                var item2 = item;
                var c     = TF.ReadFile(item);
                // replace in content
                c = SH.Replace(c, _Original, string.Empty);
                TF.SaveFile(c, item2);

                if (item2.Contains(_Original))
                {
                    string newFile = item2.Replace(_Original, string.Empty);
                    FS.MoveFile(item2, newFile, FileMoveCollisionOption.Overwrite);
                    files[i] = newFile;
                }
            }
        }
        return(files);
    }