bool CopyFiles (IProgressMonitor monitor, IWorkspaceFileObject obj, IEnumerable<FilePath> files, FilePath targetBasePath, bool ignoreExternalFiles)
{
FilePath baseDir = obj.BaseDirectory.FullPath;
foreach (FilePath file in files) {
if (!File.Exists (file)) {
monitor.ReportWarning (GettextCatalog.GetString ("File '{0}' not found.", file));
continue;
}
FilePath fname = file.FullPath;
// Can't export files from outside the root solution directory
if (!fname.IsChildPathOf (baseDir)) {
if (ignoreExternalFiles)
continue;
if (obj is Solution)
monitor.ReportError ("The solution '" + obj.Name + "' is referencing the file '" + Path.GetFileName (file) + "' which is located outside the root solution directory.", null);
else
monitor.ReportError ("The project '" + obj.Name + "' is referencing the file '" + Path.GetFileName (file) + "' which is located outside the project directory.", null);
return false;
}
FilePath rpath = fname.ToRelative (baseDir);
rpath = rpath.ToAbsolute (targetBasePath);
if (!Directory.Exists (rpath.ParentDirectory))
Directory.CreateDirectory (rpath.ParentDirectory);
File.Copy (file, rpath, true);
}
return true;
}