public CopySpec(string srcDir, string dstDir, SourceFileSpec spec, bool recursive, string[] fileList) { SourceDir = srcDir; DestDir = dstDir; FileSpec = spec; IsRecursive = recursive; FileList = fileList; }
private bool CopyBySpec(string srcDir, string dstDir, SourceFileSpec sfspec, string[] specFileList, bool isRecursive) { if (!EnsureDirectoryExists(dstDir)) { return(false); } string[] fileList; if (sfspec == SourceFileSpec.List) { fileList = specFileList; } else { fileList = Directory.GetFiles(srcDir); } foreach (string str in fileList) { // Spec list is filenames, GetFiles is paths; convert to simple filename. string fileName = Path.GetFileName(str); switch (sfspec) { case SourceFileSpec.All: case SourceFileSpec.List: // keep all break; case SourceFileSpec.NotBins: // Mostly this means "skip obj and bin dirs", which happens later. // Rather than specify everything we do want, just omit this one thing. if (fileName == "RuntimeData.csproj") { continue; } break; case SourceFileSpec.AsmSources: // Need the sources and the ca65 config files. if (!(fileName.ToUpperInvariant().EndsWith(".S") || !fileName.ToUpperInvariant().EndsWith("_cc65.cfg"))) { continue; } break; case SourceFileSpec.RegressionTests: MatchCollection matches = sTestCaseRegex.Matches(fileName); if (matches.Count != 1) { continue; } // Skip project files. Could probably do this with regex... but why. if (fileName.StartsWith("1") && fileName.EndsWith(".dis65")) { continue; } break; default: throw new Exception("Unsupported spec " + sfspec); } string srcPath = Path.Combine(srcDir, fileName); string dstPath = Path.Combine(dstDir, fileName); if (!CopyFile(srcPath, dstPath)) { return(false); } } if (isRecursive) { string[] dirList = Directory.GetDirectories(srcDir); foreach (string str in dirList) { string dirFileName = Path.GetFileName(str); if (sfspec == SourceFileSpec.NotBins && (dirFileName == "obj" || dirFileName == "bin")) { continue; } if (!CopyBySpec(Path.Combine(srcDir, dirFileName), Path.Combine(dstDir, dirFileName), sfspec, specFileList, isRecursive)) { return(false); } } } return(true); }