public async override Task GetFiles() { InitCollections(); //Get lamp files _lampshowPath = Path.Combine(_skeletonGameProvider.GameFolder, "assets\\lampshows"); if (!Directory.Exists(_lampshowPath)) { Log($"Creating lampshow directory. {_lampshowPath}"); Directory.CreateDirectory(_lampshowPath); } Log($"Retrieving Lamp/RGB Shows from {_lampshowPath}"); this.AssetFiles = new ObservableCollection <string>(); var lampshowFiles = await _skeletonGameFiles.GetFilesAsync(_lampshowPath, AssetTypes.Lampshows); foreach (var lampshow in lampshowFiles) { var lampFile = Path.GetFileName(lampshow); if (lampFile.Contains(".lampshow")) { if (!LampShows.Any(x => x.File == lampFile)) { await Dispatcher.CurrentDispatcher.InvokeAsync(() => { AssetFiles.Add(lampFile); }); } } else if (lampFile.Contains(".rgbshow")) { if (!RGBShows.Any(x => x.File == lampFile)) { await Dispatcher.CurrentDispatcher.InvokeAsync(() => { AssetFiles.Add(lampFile); }); } } } }
public override void Drop(IDropInfo dropInfo) { try { IList <LampShow> addedLampshows = new List <LampShow>(); List <string> droppedFiles = new List <string>(); //Needs a few checks here. We can be dragging in from explorer or across to the datagrid. var dragFileList = dropInfo.Data; //Dragged files from windows if (dragFileList.GetType() == typeof(DataObject)) { var windowsFileList = ((DataObject)dropInfo.Data).GetFileDropList().Cast <string>(); droppedFiles.AddRange(windowsFileList); } else { //Catch if not a list of files, just add the one that's been dropped. try { //Add files and remove them from the available list droppedFiles.AddRange((IEnumerable <string>)dragFileList); } catch (System.Exception) { var file = (string)dragFileList; droppedFiles.Add(file); } } //Null draginfo here should mean files came from windows, so add them to file list if (dropInfo.DragInfo == null) { foreach (var lampFile in droppedFiles) { if (Path.GetExtension(lampFile) == ".lampshow" || Path.GetExtension(lampFile) == ".rgbshow") { var lampFileName = Path.GetFileName(lampFile); //Don't add dupes if (!this.AssetFiles.Any(x => x == lampFile) && !this.LampShows.Any(x => x.File == lampFileName)) { //Copy the file to the lampshow path and add to list var newFilePath = Path.Combine(_lampshowPath, lampFileName); if (!File.Exists(newFilePath)) { File.Copy(lampFile, newFilePath); } this.AssetFiles.Add(lampFileName); } } } } //Convert the lampshow files to lampshow models and add to datagrid else { // Return if trying to drag to the same element if (dropInfo.DragInfo.VisualSource == dropInfo.VisualTarget) { return; } //Remove all dragged files from list foreach (var file in droppedFiles) { this.AssetFiles.Remove(file); } //Create lamp shows foreach (var lampFile in droppedFiles) { if (Path.GetExtension(lampFile) == ".lampshow" || Path.GetExtension(lampFile) == ".rgbshow") { var file = Path.GetFileName(lampFile); var key = Path.GetFileNameWithoutExtension(lampFile); addedLampshows.Add(new LampShow() { Key = key, File = Path.GetFileName(lampFile) }); } } if (addedLampshows.Count > 0) { LampShows.AddRange(addedLampshows.Where(x => x.File.Contains(".lampshow"))); RGBShows.AddRange(addedLampshows.Where(x => x.File.Contains(".rgbshow"))); } } } catch (System.Exception) { } }