private void HandleThemeDrag(object sender, BeginDragEventArgs e) { FrameworkElement frameworkElement = (FrameworkElement)sender; ThemeSummary themeSummary = frameworkElement.DataContext as ThemeSummary; IDataObject dataObject = Advent.Common.Interop.DataObject.CreateDataObject(); dataObject.SetVirtualFiles(new VirtualFile[] { new VirtualFile(themeSummary.Name + Path.GetExtension(themeSummary.ThemeFullPath), FileUtil.ReadAllBytes(themeSummary.ThemeFullPath, FileShare.ReadWrite)) }); dataObject.DoDragDrop((UIElement)sender, e.DragPoint, DragDropEffects.Copy); }
public ThemeSummary ImportTheme(string file) { if (Path.GetExtension(file).Equals(".dll", StringComparison.OrdinalIgnoreCase)) { ThemeSummary theme = this.CreateTheme(); using (MediaCenterTheme mediaCenterTheme = theme.OpenTheme()) { mediaCenterTheme.AddResourceFileDifferences(VmcStudioUtil.BackupFile(Path.Combine(MediaCenterUtil.MediaCenterPath, "ehres.dll")), file); mediaCenterTheme.Save(); } return theme; } else { string directory = Path.Combine(this.themesPath, Guid.NewGuid().ToString()); string themeFileName = Path.GetFileName(file); string str = Path.Combine(directory, themeFileName); Directory.CreateDirectory(directory); try { File.Copy(file, str); try { Dispatcher dispatcher = System.Windows.Application.Current.Dispatcher; ThemeSummary summary = new ThemeSummary(); Action action = (Action)(() => { summary.BasePath = directory; summary.ThemeFile = themeFileName; summary.Save(); this.themes.Add(summary); }); dispatcher.Invoke((Delegate)action, new object[0]); return summary; } catch (Exception ex) { Trace.TraceError("Error importing theme {0}: {1}", (object)themeFileName, (object)((object)ex).ToString()); File.Delete(str); throw; } } catch (Exception) { try { Directory.Delete(directory, true); } catch (Exception ex2) { Trace.TraceError("Could not delete failed import ({1}): {0}", (object)((object)ex2).ToString(), (object)directory); } throw; } } }
public void DeleteTheme(ThemeSummary theme) { this.themes.Remove(theme); Directory.Delete(theme.BasePath, true); }