Exemple #1
0
 public VmcStudioApp()
 {
     this.Documents = new ObservableCollection <VmcDocument>();
     this.Documents.CollectionChanged += new NotifyCollectionChangedEventHandler(this.Documents_CollectionChanged);
     this.ThemeManager = new ThemeManager(Path.Combine(VmcStudioUtil.ApplicationDataPath, "Themes"));
     using (MediaCenterLibraryCache centerLibraryCache = new MediaCenterLibraryCache(MediaCenterUtil.MediaCenterPath))
         this.StartMenuManager = StartMenuManager.Create((IResourceLibraryCache)centerLibraryCache);
     Application.Current.Resources.Add((object)"StartMenuManager", (object)this.StartMenuManager);
     this.StartMenuManager.CustomCategory = VmcStudioUtil.ApplicationName;
     this.CommonResources = new CommonResourceManager(this);
 }
Exemple #2
0
 protected void ApplyThemes(ProgressEnabledOperation operation, bool preserveMenu)
 {
     this.OnApplyingThemes(new ApplyThemesEventArgs(operation));
     try
     {
         MediaCenterLibraryCache readCache          = new MediaCenterLibraryCache(VmcStudioUtil.BackupsPath, UnmanagedLibraryAccess.Read);
         MediaCenterLibraryCache writeCache         = new MediaCenterLibraryCache(MediaCenterUtil.MediaCenterPath, UnmanagedLibraryAccess.Write);
         MemoryLibraryCache      memoryLibraryCache = (MemoryLibraryCache)null;
         if (preserveMenu)
         {
             memoryLibraryCache = new MemoryLibraryCache((ushort)1033);
             using (MediaCenterLibraryCache centerLibraryCache = new MediaCenterLibraryCache())
                 StartMenuManager.Create((IResourceLibraryCache)centerLibraryCache).Save((IResourceLibraryCache)memoryLibraryCache, true);
         }
         readCache.LibraryLoading  += (EventHandler <LibraryLoadEventArgs>)((sender, e) => VmcStudioUtil.BackupFile(Path.Combine(MediaCenterUtil.MediaCenterPath, e.FileName)));
         writeCache.LibraryLoading += (EventHandler <LibraryLoadEventArgs>)((sender, e) =>
         {
             string local_0 = VmcStudioUtil.BackupFile(Path.Combine(MediaCenterUtil.MediaCenterPath, e.FileName));
             string local_1 = Path.Combine(writeCache.SearchPath, e.FileName);
             VmcStudioUtil.TakeOwnership(local_1);
             File.Copy(local_0, local_1, true);
             VmcStudioUtil.TakeOwnership(local_1);
         });
         if (Directory.Exists(VmcStudioUtil.BackupsPath))
         {
             foreach (string path in Directory.GetFiles(VmcStudioUtil.BackupsPath))
             {
                 writeCache.LoadLibrary(Path.GetFileName(path));
             }
         }
         int       num = 0;
         int       operationCompleted  = 0;
         Exception applyException      = (Exception)null;
         List <MediaCenterTheme> list1 = Enumerable.ToList <MediaCenterTheme>(Enumerable.Select <ThemeSummary, MediaCenterTheme>((IEnumerable <ThemeSummary>) this.AppliedThemes, (Func <ThemeSummary, MediaCenterTheme>)(o => o.OpenTheme())));
         try
         {
             List <IDelayedProgressOperation> list2 = new List <IDelayedProgressOperation>();
             foreach (MediaCenterTheme mediaCenterTheme in list1)
             {
                 IDelayedProgressOperation applyOperation = mediaCenterTheme.CreateApplyOperation(readCache, writeCache);
                 num += applyOperation.Count;
                 applyOperation.Progress  += (EventHandler <ProgressEventArgs>)((sender, args) => operation.OnProgress(args.Message, args.CurrentIndex + operationCompleted));
                 applyOperation.Abandoned += (EventHandler <ExceptionEventArgs>)((sender, args) => applyException = args.Exception);
                 list2.Add(applyOperation);
             }
             operation.Count = num;
             using (readCache)
             {
                 using (writeCache)
                 {
                     foreach (IDelayedProgressOperation progressOperation in list2)
                     {
                         operation.Description = progressOperation.Description;
                         progressOperation.Start();
                         progressOperation.WaitForCompletion();
                         if (applyException != null)
                         {
                             throw applyException;
                         }
                         operationCompleted += progressOperation.Count;
                     }
                     if (this.AppliedThemes.Count > 0)
                     {
                         IResource resource = writeCache["ehres.dll"].GetResource("VmcStudio.Themes.xml", (object)23);
                         using (MemoryStream memoryStream = new MemoryStream())
                         {
                             new XmlSerializer(typeof(ThemeManager.AppliedThemesDocument)).Serialize((Stream)memoryStream, (object)new ThemeManager.AppliedThemesDocument()
                             {
                                 AppliedThemes = Enumerable.ToArray <ThemeSummary>((IEnumerable <ThemeSummary>) this.AppliedThemes)
                             });
                             memoryStream.Flush();
                             ResourceExtensions.Update(resource, memoryStream.GetBuffer());
                         }
                     }
                     if (memoryLibraryCache != null)
                     {
                         memoryLibraryCache.ApplyTo((IResourceLibraryCache)writeCache);
                     }
                 }
             }
             this.IsDirty = false;
         }
         finally
         {
             foreach (MediaCenterTheme mediaCenterTheme in list1)
             {
                 mediaCenterTheme.Dispose();
             }
         }
     }
     catch (Exception ex)
     {
         Trace.TraceError(((object)ex).ToString());
         operation.OnAbandoned(ex);
         throw;
     }
     operation.OnCompleted();
 }