public bool Initialize()
        {
            if (!File.Exists("ZuneDBApi.dll"))
            {
                throw new FileNotFoundException(
                          "Could not find ZuneDBApi.dll. Are you sure Zune Social Tagger is installed in the Zune application folder?");
            }

            //Just copying what the zune software does internally here to initialize the database
            _zuneLibrary = new ZuneLibrary();

            bool dbRebult;

            //anything other than 0 means an error occured reading the database
            int num = _zuneLibrary.Initialize(null, out dbRebult);

            if (num > -1)
            {
                int phase2;
                _zuneLibrary.Phase2Initialization(out phase2);
                _zuneLibrary.CleanupTransientMedia();
            }
            else
            {
                return(false);
            }

            return(true);
        }
예제 #2
0
파일: ZuneApi.cs 프로젝트: quad341/zpd
        // Using http://blog.ctaggart.com/2010/08/query-zune-music-collection-with-f.html#!/2010/08/query-zune-music-collection-with-f.html as a base
        // Also found some help at http://averagedeveloper.blogspot.com/2012/04/querying-zunedbapidll.html
        /// <summary>
        /// Reindexes the music by iterating through all music in the Zune Library and saving it in the local Lucene database. Required for search to work correctly
        /// </summary>
        /// <seealso cref="Search"/>
        public void ReIndexMusic()
        {
            var library = new ZuneLibrary();
            var dbReloaded = false;
            int returnValue = library.Initialize(null, out dbReloaded);
            if (returnValue >= 0)
            {
                library.Phase2Initialization(out returnValue);
                if (returnValue >= 0)
                {
                    library.CleanupTransientMedia();

                    ZuneQueryList searchResult = library.QueryDatabase(EQueryType.eQueryTypeAllTracks, 0, EQuerySortType.eQuerySortOrderNone, 0, null);
                    if (null != searchResult)
                    {
                        // we have results, index them
                        var writer = new IndexWriter(new SimpleFSDirectory(new DirectoryInfo(LUCENE_INDEX_DIRECTORY)), new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29), true, IndexWriter.MaxFieldLength.UNLIMITED);
                        for (uint i = 0; i < searchResult.Count; i++)
                        {
                            // add a document for each song. We will only store the mediaId and mediaTypeId and store+index the title, artist, and album
                            var doc = new Document();

                            var mediaId = (UInt32)searchResult.GetFieldValue(i, typeof(UInt32), (uint)MicrosoftZuneLibrary.SchemaMap.kiIndex_MediaID);
                            var mediaTypeId = (UInt32)searchResult.GetFieldValue(i, typeof(UInt32), (uint)MicrosoftZuneLibrary.SchemaMap.kiIndex_MediaType);
                            var duration = (UInt32)searchResult.GetFieldValue(i, typeof(UInt32), (uint)MicrosoftZuneLibrary.SchemaMap.kiIndex_Duration);
                            var artist = (String)searchResult.GetFieldValue(i, typeof(String), (uint)MicrosoftZuneLibrary.SchemaMap.kiIndex_DisplayArtist);
                            var title = (String)searchResult.GetFieldValue(i, typeof(String), (uint)MicrosoftZuneLibrary.SchemaMap.kiIndex_Title);
                            var album = (String)searchResult.GetFieldValue(i, typeof(String), (uint)MicrosoftZuneLibrary.SchemaMap.kiIndex_WMAlbumTitle);

                            doc.Add(new Field("mediaId", mediaId.ToString(), Field.Store.YES, Field.Index.NO));
                            doc.Add(new Field("mediaTypeId", mediaTypeId.ToString(), Field.Store.YES, Field.Index.NO));
                            doc.Add(new Field("duration", duration.ToString(), Field.Store.YES, Field.Index.NO));
                            doc.Add(new Field("artist", artist, Field.Store.YES, Field.Index.ANALYZED));
                            doc.Add(new Field("title", title, Field.Store.YES, Field.Index.ANALYZED));
                            doc.Add(new Field("album", album, Field.Store.YES, Field.Index.ANALYZED));

                            writer.AddDocument(doc);
                        }
                        writer.Commit();
                        writer.Close();
                    }
                }
            }
        }
예제 #3
0
        public static int Launch(string strArgs, IntPtr hWndSplashScreen)
        {
            PerfTrace.PerfTrace.PERFTRACE_LAUNCHEVENT(PerfTrace.PerfTrace.LAUNCH_EVENT.IN_MANAGED_LAUNCH, 0U);
            Application.ErrorReport += new ErrorReportHandler(ErrorReportHandler);
            Hashtable hashtable = StandAlone.Startup(SplitCommandLineArguments(strArgs), DefaultCommandLineParameterSwitch);

            if (hashtable != null)
            {
                _unprocessedAppArgs = new List <Hashtable>();
                _unprocessedAppArgs.Add(hashtable);
            }
            DialogHelper.DialogCancel = ZuneUI.Shell.LoadString(StringId.IDS_DIALOG_CANCEL);
            DialogHelper.DialogYes    = ZuneUI.Shell.LoadString(StringId.IDS_DIALOG_YES);
            DialogHelper.DialogNo     = ZuneUI.Shell.LoadString(StringId.IDS_DIALOG_NO);
            DialogHelper.DialogOk     = ZuneUI.Shell.LoadString(StringId.IDS_DIALOG_OK);
            XmlDataProviders.Register();
            LibraryDataProvider.Register();
            SubscriptionDataProvider.Register();
            StaticLibraryDataProvider.Register();
            AggregateDataProviderQuery.Register();
            ZuneUI.Shell.InitializeInstance();
            Application.Name           = "Zune";
            Application.Window.Caption = "Zune";
            Application.Window.SetIcon("ZuneShellResources.dll", 1);
            Application.Window.AlwaysOnTop = true;
            if (!hashtable.Contains("noshadow"))
            {
                Image[]    images      = new Image[4];
                ImageInset imageInset1 = new ImageInset(26, 0, 30, 0);
                ImageInset imageInset2 = new ImageInset(0, 10, 0, 0);
                images[0] = new Image("res://ZuneShellResources.dll!activeshadowLeft.png", imageInset2);
                images[1] = new Image("res://ZuneShellResources.dll!activeshadowTop.png", imageInset1);
                images[2] = new Image("res://ZuneShellResources.dll!activeshadowRight.png", imageInset2);
                images[3] = new Image("res://ZuneShellResources.dll!activeshadowBottom.png", imageInset1);
                Application.Window.SetShadowEdgeImages(true, images);
                imageInset1 = new ImageInset(23, 0, 29, 0);
                imageInset2 = new ImageInset(0, 5, 0, 0);
                images[0]   = new Image("res://ZuneShellResources.dll!inactiveshadowLeft.png", imageInset2);
                images[1]   = new Image("res://ZuneShellResources.dll!inactiveshadowTop.png", imageInset1);
                images[2]   = new Image("res://ZuneShellResources.dll!inactiveshadowRight.png", imageInset2);
                images[3]   = new Image("res://ZuneShellResources.dll!inactiveshadowBottom.png", imageInset1);
                Application.Window.SetShadowEdgeImages(false, images);
            }
            Application.Window.CloseRequested += new WindowCloseRequestedHandler(CodeDialogManager.Instance.OnWindowCloseRequested);
            CodeDialogManager.Instance.WindowCloseNotBlocked += new EventHandler(OnWindowCloseNotBlocked);
            Application.Window.SessionConnected += new SessionConnectedHandler(OnSessionConnected);
            string source = "res://ZuneShellResources!Frame.uix#Frame";

            _hWndSplashScreen       = hWndSplashScreen;
            _initializationFailsafe = new InitializationFailsafe();
            PerfTrace.PerfTrace.PERFTRACE_LAUNCHEVENT(PerfTrace.PerfTrace.LAUNCH_EVENT.REQUEST_UI_LOAD, 0U);
            Application.Window.RequestLoad(source);
            PerfTrace.PerfTrace.PERFTRACE_LAUNCHEVENT(PerfTrace.PerfTrace.LAUNCH_EVENT.REQUEST_UI_LOAD_COMPLETE, 0U);
            CallbackOnUIThread callbackOnUiThread = new CallbackOnUIThread();

            _appInitializationSequencer = new AppInitializationSequencer(new CorePhase2ReadyCallback(CorePhase3Ready));
            _zuneLibrary = new ZuneLibrary();
            HRESULT num = _zuneLibrary.Initialize(null, out _dbRebuilt);

            if (num.IsSuccess)
            {
                StandAlone.Run(new DeferredInvokeHandler(Phase2Initialization));
                Application.Window.CloseRequested -= new WindowCloseRequestedHandler(CodeDialogManager.Instance.OnWindowCloseRequested);
                CodeDialogManager.Instance.WindowCloseNotBlocked -= new EventHandler(OnWindowCloseNotBlocked);
                Application.Window.SessionConnected -= new SessionConnectedHandler(OnSessionConnected);
                if (Download.IsCreated)
                {
                    Download.Instance.Dispose();
                }
                ZuneShell.DefaultInstance?.Dispose();
                ViewTimeLogger.Instance.Shutdown();
                if (PodcastCredentials.HasInstance)
                {
                    PodcastCredentials.Instance.Dispose();
                }
                if (ProxyCredentials.HasInstance)
                {
                    ProxyCredentials.Instance.Dispose();
                }
                StandAlone.Shutdown();
                HttpWebRequest.Shutdown();
                WorkerQueue.ShutdownAll();
                if (ContentRefreshTask.HasInstance)
                {
                    ContentRefreshTask.Instance.Dispose();
                }
                if (Service != null)
                {
                    Service.Dispose();
                }
                if (ShellMessagingNotifier.HasInstance)
                {
                    ShellMessagingNotifier.Instance.Dispose();
                }
                if (MessagingService.HasInstance)
                {
                    MessagingService.Instance.Dispose();
                }
                if (FeaturesChangedApi.HasInstance)
                {
                    FeaturesChangedApi.Instance.Dispose();
                }
                CDAccess.Instance.Dispose();
                PlaylistManager.Instance.Dispose();
                if (_interopNotifications != null)
                {
                    _interopNotifications.ShowErrorDialog -= new OnShowErrorDialogHandler(OnShowErrorDialog);
                    _interopNotifications.Dispose();
                    _interopNotifications = null;
                }
            }
            _zuneLibrary.Dispose();
            return(num.Int);
        }