public void Create(object param)
{
var fullProjectPath = DirectoryPath;
if (CreateProjectDirectory)
{
var invalidChars = System.IO.Path.GetInvalidPathChars();
var nameFolder = new String(Name
.Where(x => !invalidChars.Contains(x))
.ToArray());
fullProjectPath = System.IO.Path.Combine(fullProjectPath, nameFolder);
}
var document = _projectFactory.CreateNew(fullProjectPath);
document.Name = Name;
document.Author = Author;
_dataService.SaveProject(document);
var resBasePath = "resources/includes";
var includes = GetResourcesUnder(resBasePath).ToDictionary(n => n, n => n.Substring(resBasePath.Length + 1));
foreach (var p in includes)
{
var resPath = p.Value;
var filePath = Path.Combine(fullProjectPath, resPath);
var stream = System.Windows.Application.GetResourceStream(new Uri(p.Key, UriKind.Relative)).Stream;
WriteResourceToFile(filePath, stream);
}
var embeddedKey = "Resources.Includes.";
var embeddedIncludes = Assembly.GetExecutingAssembly().GetManifestResourceNames()
.Where(n => n.Contains(embeddedKey))
.ToDictionary(n => n, n => EmbedPathToFilePath(n, embeddedKey));
foreach (var p in embeddedIncludes)
{
var filePath = Path.Combine(fullProjectPath, p.Value);
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(p.Key);
WriteResourceToFile(filePath, stream);
}
var allPaths = includes.Values.Concat(embeddedIncludes.Values);
var folders = allPaths.Select(p => p.Split('/')[0]).Distinct();
document.Project.AddIncludeFolders(folders);
document.MusicNsf = document.EffectsNsf = fullProjectPath + "/sound/mm5.nsf";
_dataService.SaveProject(document);
var args = new ProjectOpenedEventArgs() { Project = document };
ViewModelMediator.Current.GetEvent<ProjectOpenedEventArgs>().Raise(this, args);
}