internal static string[] CacheMoviesSection
            (IMLSection section)
        {
            MainImportingEngine.CurrentProgress = 0;
            MainImportingEngine.ThisProgress.Progress
                (MainImportingEngine.CurrentProgress,
                "Caching Movies section...");


            int[] itemIDs = section != null
                         ?  section.GetAllItemIDs()
                         :  new int[]
            {
            };


            int itemsCount = itemIDs.Length;

            string[] filmLocations = new string[itemsCount];
            int      cacheCounter  = 0;


            foreach (IMLItem item in itemIDs.Select
                         (id => section != null ? section.FindItemByID(id) : null))
            {
                filmLocations[cacheCounter]
                    = item.Location;

                cacheCounter++;
            }

            return(filmLocations);
        }
Beispiel #2
0
        internal static bool UpdateMoviesSection
            (string pluginpath,
            IBaseSystem iBaseSystem,
            IEnumerable <string> combinedSceneTags,
            IMLSection section)
        {
            if (section.ItemCount == 0)
            {
                return(true);
            }



            Debugger.LogMessageToFile
                (Environment.NewLine
                + Environment.NewLine
                + "Film Updater is enabled.");



            #region Pre-Updating Operations


            Debugger.LogMessageToFile
                ("Initializing section variables...");


            int totalItems
                = section.ItemCount;


            int currentItem = 1;


            MainImportingEngine
            .CurrentProgress = 0;


            MainImportingEngine
            .GeneralStatus
                = "Updating Movies Section";


            MainImportingEngine
            .SpecialStatus = "";


            #endregion



            #region Main Updating Loop


            Debugger.LogMessageToFile
                ("Beginning to update" +
                " Films section...");



            section.BeginUpdate();



            foreach (int id in section.GetAllItemIDs())
            {
                if (!SingleMovieItemUpdater
                    .UpdateFilmItem
                        (id, section,
                        pluginpath,
                        ref currentItem,
                        totalItems,
                        iBaseSystem,
                        combinedSceneTags))
                {
                    return(false);
                }
            }



            section.EndUpdate();


            Debugger.LogMessageToFile
                ("Completing updating" +
                " of Films section...");


            #endregion



            return(true);
        }
        internal static string[] CacheMoviesSection(IMLSection section)
        {
            MainImportingEngine.CurrentProgress = 0;
            MainImportingEngine.ThisProgress.Progress
                (MainImportingEngine.CurrentProgress,
                "Caching Movies section...");

            int[] itemIDs = section != null
                         ?  section.GetAllItemIDs()
                         :  new int[] { };

            int itemsCount = itemIDs.Length;
            string[] filmLocations = new string[itemsCount];
            int cacheCounter = 0;

            foreach (IMLItem item in itemIDs.Select
                (id => section != null ? section.FindItemByID(id) : null))
            {

                filmLocations[cacheCounter]
                    = item.Location;

                cacheCounter++;

            }

            return filmLocations;
        }
        internal static void ImportPcGames(IMLImportProgress progress, IMLSection gamesSection)
        {

            if ((!Settings.EnableGamesUpdater && !Settings.EnableGamesImporter))
                return;
                            
            if (String.IsNullOrEmpty(Settings.GameShortcutsLocation) )
                return;

            if ( !File.Exists(Settings.GameShortcutsLocation) )
            return;


            Importer.ThisProgress = progress;
            //Importer.GeneralStatus = "Updating Games Section";
            Importer.SpecialStatus = String.Empty;
            Importer.ThisProgress.Progress(Importer.CurrentProgress, "Updating Games Section...");

            DirectoryInfo pcGamesFolder = new DirectoryInfo(Settings.GameShortcutsLocation);
            FileInfo[] shortcuts = pcGamesFolder.GetFiles("*.lnk", SearchOption.AllDirectories);
            //IMLSection GamesSection = Importer.library.FindSection("Games", true);

            #region Man importing engine

            int itemCounter = 0;
            WshShell shell = new WshShellClass();

            gamesSection.BeginUpdate();

            foreach (FileInfo shortcut in shortcuts)
            {
                int progressStep = 100 / shortcuts.Length;
                Importer.CurrentProgress = 100 - (progressStep * (shortcuts.Length - itemCounter));

                ImportPcGame(shell, shortcut.FullName, gamesSection);
                itemCounter++;
            }

            gamesSection.EndUpdate();

            #endregion

            #region Update

            if (!Settings.EnableGamesUpdater) return;


           

            gamesSection.BeginUpdate();
            itemCounter = 0;
            int[] allItemIDs = gamesSection.GetAllItemIDs();

            foreach (int id in allItemIDs)
            {
                IMLItem item = gamesSection.FindItemByID(id);
                int progressStep = 100 / allItemIDs.Length;
                Importer.CurrentProgress = 100 - (progressStep * (allItemIDs.Length - itemCounter));
                Downloaders.DownloadGameDetailsFromMobyGames(item);

                Helpers.UserCancels(Importer.SpecialStatus, item);

                itemCounter++;
            }

            gamesSection.EndUpdate();
            
            

            #endregion

        } //endof function
        private static bool TryToPerfrormMediaSectionUpdate(IMLSection section, string pluginPath, 
            string[] videoExtensions,
            string[] videoExtensionsCommon,
            int totalSectionItems)
        {
            try
            {

                int currentSectionItem = 1;
                section.BeginUpdate();
                Helpers.LogMessageToFile
                    ("Section update was started.");

                if (section.GetAllItemIDs().Any
                    (id => !SingleMovieItemUpdater.UpdateSectionItem
                        (id, section, pluginPath, ref currentSectionItem,
                         totalSectionItems, videoExtensions,
                         videoExtensionsCommon)))
                {
                    return false;
                }

                section.EndUpdate();
                Helpers.LogMessageToFile
                    ("Section update is complete.");

            }
            catch (Exception e)
            {
                AcknowledgeMediaSectionUpdaterErrorAndTerminateImportSequence(e);
            }

            return true;
        }
        //TODO: Refactor BackupMediaSection Method
        public static bool LibrarySynchronizerBackupMediaSection
            (IMLSection section, string xmlDirectory)
        {

            string xmlFilename = section.Name + ".xml";

            #region Construct XML file path
            string xmlPath;

            if (xmlDirectory.EndsWith("\\"))
                xmlPath = xmlDirectory + xmlFilename;
            else
                xmlPath = xmlDirectory + "\\" + xmlFilename;

            #endregion
            

            try
            {

                #region create basic structure
                MainImportingEngine.ThisProgress.Progress(MainImportingEngine.CurrentProgress, "Creating backup for section " + section.Name + "...");
                Thread.Sleep(1000);
                // Create the xml document container
                XmlDocument doc = new XmlDocument();
                // Create the XML Declaration, and append it to XML document
                XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", null, null);
                doc.AppendChild(dec);
                //Create the root element
                XmlElement root = doc.CreateElement("Library");
                doc.AppendChild(root);
                #endregion

                bool alreadyShowedError = false;
                foreach (int id in section.GetAllItemIDs())
                {
                    // Create Film structure
                    XmlElement item = doc.CreateElement("item");
                    IMLItem Item = section.FindItemByID(id);

                    #region Read key tags
                    XmlElement name = doc.CreateElement("name");
                    name.InnerText = Item.Name;
                    item.AppendChild(name);

                    XmlElement location = doc.CreateElement("location");
                    location.InnerText = Item.Location;
                    item.AppendChild(location);
                    #endregion

                    #region Read the rest of the tags
                    foreach (string TagName in (string[])section.GetTagNames())
                    {
                        if (TagName.Contains(" ") && !alreadyShowedError)
                        {
                            //StatusForm.statusForm.TrayIcon.ShowBalloonTip(5000, "Invalid Tag Name", "The tag '" + TagName + "' in your " + Section.Name + " section contains one or more space characters. Tags with space characters are invalid for xml files. For this reason, the tag's name will be saved with those characters removed. Please note however that if this tag was created by another plugin or a script, said plugin will not be able to read this tag in case you restore your library. Please report this issue to the plugin's developer, in order to be acknowledged and fixed.", ToolTipIcon.Error);
                            //Thread.Sleep(5000);
                            alreadyShowedError = true;
                        }

                        string elementName = TagName.Replace(" ", "");
                        XmlElement element = doc.CreateElement(elementName);
                        element.InnerText = Helpers.GetTagValueFromItem(Item, TagName);
                        item.AppendChild(element);
                    }
                    #endregion

                    root.AppendChild(item);
                }

                #region Finalize and save xml file           
                //string xmlOutput = doc.OuterXml;
                try
                {
                    doc.Save(xmlPath);
                    //File.WriteAllText(xmlpath, xmlOutput);
                }
                catch (Exception e)
                {
                    Debugger.LogMessageToFile("Unable to save an xml backup of your media section to: " + xmlPath + ". The error was: " + e );
                    //StatusForm.statusForm.TrayIcon.ShowBalloonTip(10000, "Access to a media directory was rectricted", "MediaFairy could not write a Section backup XML file in the directory " + xmlDirectory + " because Windows security privileges do not allow modification for this directory.", ToolTipIcon.Warning);
                    //Thread.Sleep(2000);
                    return false;
                }
                #endregion


            }
            catch (Exception e)
            {
                StatusForm.statusForm.TrayIcon.ShowBalloonTip(10000, "Error writing XML backup", "An unexpected error ocurred while trying to save an XML backup of your media sections. Please see Debug.log for details.", ToolTipIcon.Error);
                Debugger.LogMessageToFile("An unexpected error ocurred while trying to save an XML backup of a media section. The error was: " + e);
                return false;
            }

            return true;
        }
        internal static bool UpdateMoviesSection(string pluginpath,
             IBaseSystem iBaseSystem,
             IEnumerable<string> combinedSceneTags,
             IMLSection section)
        {
            if (section.ItemCount == 0)
                return true;

            Debugger.LogMessageToFile
                (Environment.NewLine
                + Environment.NewLine
                + "Film Updater is enabled.");

            #region Pre-Updating Operations

            Debugger.LogMessageToFile
                ("Initializing section variables...");

            int totalItems
                = section.ItemCount;

            int currentItem = 1;

            MainImportingEngine
                .CurrentProgress = 0;

            MainImportingEngine
                .GeneralStatus
                = "Updating Movies Section";

            MainImportingEngine
                .SpecialStatus = "";

            #endregion

            #region Main Updating Loop

            Debugger.LogMessageToFile
                ("Beginning to update" +
                 " Films section...");

            section.BeginUpdate();

            foreach (int id in section.GetAllItemIDs())
            {

                if (!SingleMovieItemUpdater
                    .UpdateFilmItem
                    (id, section,
                     pluginpath,
                     ref currentItem,
                     totalItems,
                    iBaseSystem,
                    combinedSceneTags))
                    return false;

            }

            section.EndUpdate();

            Debugger.LogMessageToFile
                ("Completing updating" +
                 " of Films section...");

            #endregion

            return true;
        }