Example #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;
     }
 }
        private void BrowseButton_Click(object sender, RoutedEventArgs e)
        {
            string imageFile = VmcStudioUtil.GetImageFile();

            if (imageFile != null)
            {
                this.ThemeItem.Image = BitmapDecoder.Create(new Uri(imageFile), BitmapCreateOptions.None, BitmapCacheOption.Default).Frames[0];
            }
        }
Example #3
0
 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;
         }
     }
 }
        private ImageSource BrowseForImage()
        {
            string imageFile = VmcStudioUtil.GetImageFile();

            if (imageFile != null)
            {
                MemoryStream bitmapStream = new MemoryStream(File.ReadAllBytes(imageFile));
                return(BitmapFrame.Create(bitmapStream));
            }
            return(null);
        }
Example #5
0
        public IProgressEnabledOperation ApplyThemesAsync(bool verifyBeforeClose, bool preserveMenu)
        {
            VmcStudioUtil.EnsureMediaCenterClosed(verifyBeforeClose);
            ProgressEnabledOperation enabledOperation = new ProgressEnabledOperation()
            {
                Description = "Preparing..."
            };

            ThreadPool.QueueUserWorkItem((WaitCallback)(state => this.ApplyThemes((ProgressEnabledOperation)state, preserveMenu)), (object)enabledOperation);
            return((IProgressEnabledOperation)enabledOperation);
        }
Example #6
0
        private void ImportImagesExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            ImagesCategoryModel imagesCategory = this.Document.Theme.ImagesCategory;

            string[] imageFiles = VmcStudioUtil.GetImageFiles();
            if (imageFiles != null)
            {
                imagesCategory.Import(imageFiles);
                this.Document.Theme.UpdateVisibility();
            }
            e.Handled = true;
        }
 private void InsertVideoExecuted(object sender, ExecutedRoutedEventArgs e)
 {
     this.InsertResource(VmcStudioUtil.GetVideoFiles(), MediaType.Video);
     e.Handled = true;
 }
Example #8
0
        private void NewGameExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            OemManager oemManager = this.m_startMenu.StartMenuManager.OemManager;
            Game       game       = (Game)e.Parameter;

            Advent.MediaCenter.StartMenu.OEM.EntryPoint entryPoint = new Advent.MediaCenter.StartMenu.OEM.EntryPoint();
            entryPoint.ID                   = "{" + Guid.NewGuid() + "}";
            entryPoint.Title                = game.Name;
            entryPoint.RawDescription       = game.Description;
            entryPoint.CapabilitiesRequired = (EntryPointCapabilities.DirectX | EntryPointCapabilities.IntensiveRendering);
            entryPoint.NowPlayingDirective  = "stop";
            entryPoint.ImageOverride        = game.Image;
            string fileName  = "";
            string arguments = "";

            if (VmcStudioUtil.IsShortcut(game.PlayTasks[0]))
            {
                WshShell     shell       = new WshShell();
                IWshShortcut wshShortcut = (IWshShortcut)shell.CreateShortcut(game.PlayTasks[0]);
                fileName  = wshShortcut.TargetPath;
                arguments = wshShortcut.Arguments;
            }
            else
            {
                fileName  = game.PlayTasks[0];
                arguments = null;
            }
            entryPoint.AddIn = typeof(VmcExecuteAddIn).AssemblyQualifiedName;
            ExecutionInfo executionInfo = new ExecutionInfo();

            executionInfo.FileName  = fileName;
            executionInfo.Arguments = arguments;
            executionInfo.CloseKeys = new List <Keys>
            {
                Keys.BrowserBack
            };
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(ExecutionInfo));
            StringBuilder stringBuilder = new StringBuilder();

            xmlSerializer.Serialize(new StringWriter(stringBuilder), executionInfo);
            entryPoint.Context = stringBuilder.ToString();
            Advent.MediaCenter.StartMenu.OEM.Application application = oemManager.Applications[game.GameID];
            if (application == null)
            {
                application       = new Advent.MediaCenter.StartMenu.OEM.Application();
                application.ID    = "{" + Guid.NewGuid() + "}";
                application.Title = entryPoint.Title;
                oemManager.Applications.Add(application);
            }
            entryPoint.Manager     = oemManager;
            entryPoint.Application = application;
            oemManager.EntryPoints.Add(entryPoint);
            OemQuickLink oemQuickLink = new OemQuickLink(oemManager);

            oemQuickLink.BeginInit();
            oemQuickLink.Application = application;
            oemQuickLink.EntryPoint  = entryPoint;
            oemQuickLink.EndInit();
            oemManager.Categories["Services\\Games"].QuickLinks.Add(oemQuickLink);
            EntryPointDocumentView.OpenDocument(entryPoint);
            e.Handled = true;
        }
Example #9
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();
 }
Example #10
0
 public void ApplyThemes(bool verifyBeforeClose, bool preserveMenu)
 {
     VmcStudioUtil.EnsureMediaCenterClosed(verifyBeforeClose);
     this.ApplyThemes(new ProgressEnabledOperation(), preserveMenu);
 }