Пример #1
0
 private void SaveExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
     try
     {
         VmcStudioUtil.Application.CommonResources.CloseResources();
         try
         {
             using (MediaCenterLibraryCache mediaCenterLibraryCache = new MediaCenterLibraryCache(MediaCenterUtil.MediaCenterPath, UnmanagedLibraryAccess.Write))
             {
                 MemoryLibraryCache memoryLibraryCache = new MemoryLibraryCache(1033);
                 VmcStudioUtil.Application.StartMenuManager.Save(memoryLibraryCache);
                 foreach (string current in memoryLibraryCache.Libraries)
                 {
                     mediaCenterLibraryCache.LoadLibrary(current);
                 }
                 VmcStudioUtil.PrepareForSave(mediaCenterLibraryCache);
                 memoryLibraryCache.ApplyTo(mediaCenterLibraryCache);
             }
         }
         finally
         {
             VmcStudioUtil.Application.CommonResources.ResetResources();
         }
     }
     catch (Win32Exception ex)
     {
         if (ex.NativeErrorCode != 5)
         {
             throw;
         }
         Trace.TraceError("Failed to save changes: {0}", new object[]
         {
             ex.ToString()
         });
         System.Windows.MessageBox.Show(AccessDeniedMessage, VmcStudioUtil.ApplicationTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
     }
     catch (UnauthorizedAccessException ex2)
     {
         Trace.TraceError("Failed to save changes: {0}", new object[]
         {
             ex2.ToString()
         });
         System.Windows.MessageBox.Show(AccessDeniedMessage, VmcStudioUtil.ApplicationTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
     }
     catch (VmcStudioException ex3)
     {
         Trace.TraceError("Failed to save changes: {0}", new object[]
         {
             ex3.ToString()
         });
         System.Windows.MessageBox.Show("Failed to save changes:\n" + ex3.ToString(), VmcStudioUtil.ApplicationTitle, MessageBoxButton.OK, MessageBoxImage.Hand);
     }
     finally
     {
         Mouse.OverrideCursor = null;
     }
 }
Пример #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();
 }