예제 #1
0
        private static CataloguesIndex InitializeNoCatalogues(MoviestormPaths pMoviestormPaths, out string pErrorText)
        {
            CataloguesIndex cataloguesIndex = new CataloguesIndex();

            cataloguesIndex.Catalogues = new List <CatalogueInfo>();

            AddonPackageSet packageSet = new AddonPackageSet(pMoviestormPaths, null)
            {
                Description = "Default catalogue"
            };

            packageSet.Save(out pErrorText, cataloguesIndex.DefaultAddonDatabaseFilename);
            CatalogueInfo catalogue = new CatalogueInfo()
            {
                Name               = cataloguesIndex.DefaultAddonDatabase,
                Description        = "Default catalogue",
                AddonCount         = 0,
                LastUpdateDateTime = packageSet.LastUpdate,
                Version            = packageSet.CatalogueVersion
            };

            cataloguesIndex.Catalogues.Add(catalogue);
            cataloguesIndex.Save(CataloguesIndexFilePath, out pErrorText);

            return(cataloguesIndex);
        }
예제 #2
0
        // -------------------------------------------------------------------------------------------------


        public static CataloguesIndex Initialize(MoviestormPaths pMoviestormPaths, out string pErrorText)
        {
            pErrorText = null;

            List <string> catalogueFiles = Directory.EnumerateFiles(Utils.GetExecutableDirectory(), "*.scat").ToList();

            if ((catalogueFiles == null) || (catalogueFiles.Count == 0))
            {
                return(InitializeNoCatalogues(pMoviestormPaths, out pErrorText));
            }

            int defaultIndex = -1;
            int index        = 0;

            List <CatalogueInfo> catalogues = new List <CatalogueInfo>();

            foreach (string file in catalogueFiles)
            {
                CatalogueInfo catalogue = new CatalogueInfo()
                {
                    Name = Path.GetFileNameWithoutExtension(file)
                };
                string          errorText;
                AddonPackageSet packageSet = AddonPackageSet.Load(out errorText, file);
                catalogue.Description = packageSet?.Description;

                if ((catalogue.FilePath.ToLower() == AddonPackageSet.DefaultAddonPackageSetFileName.ToLower()) ||
                    (catalogueFiles.Count == 1))
                {
                    if (catalogue.Description == null)
                    {
                        catalogue.Description = "Default catalogue";
                    }
                    defaultIndex = index;
                }

                catalogue.LastUpdateDateTime = packageSet.LastUpdate;
                catalogue.AddonCount         = packageSet?.Addons.Count ?? 0;
                catalogue.Version            = packageSet.CatalogueVersion;

                catalogues.Add(catalogue);
                index++;
            }

            CataloguesIndex cataloguesIndex = new CataloguesIndex();

            cataloguesIndex.Catalogues = catalogues.OrderBy(o => o.FilePath).ToList();

            cataloguesIndex.DefaultAddonDatabase =
                (defaultIndex < 0)
                    ? cataloguesIndex.Catalogues[0].Name
                    : cataloguesIndex.Catalogues[defaultIndex].Name;

            cataloguesIndex.Save(CataloguesIndexFilePath, out pErrorText);
            return(cataloguesIndex);
        }
예제 #3
0
        public int Update(string pName, string pDescription = null, int?pAddonCount = null,
                          DateTime?pLastUpdate = null, string pVersion = null, bool pAutoSave = true)
        {
            if (string.IsNullOrEmpty(pName = pName?.Trim()))
            {
                return(-1);
            }

            int index = GetIndexByName(pName);

            bool newCatalogue = (index < 0);

            CatalogueInfo updatedCatalogueInfo = newCatalogue
                    ? new CatalogueInfo()
            {
                Name = pName
            }
                    : (CatalogueInfo)Catalogues[index].Clone();
            bool needsToSave = false;

            if (!string.IsNullOrEmpty(pDescription = pDescription?.Trim()))
            {
                if (newCatalogue || (pDescription != updatedCatalogueInfo.Description))
                {
                    updatedCatalogueInfo.Description = pDescription;
                    needsToSave = true;
                }
            }

            if (pAddonCount.HasValue && (newCatalogue || pAddonCount.Value != updatedCatalogueInfo.AddonCount))
            {
                updatedCatalogueInfo.AddonCount = pAddonCount.Value;
                needsToSave = true;
            }

            if (pLastUpdate.HasValue && (newCatalogue || pLastUpdate.Value != updatedCatalogueInfo.LastUpdateDateTime))
            {
                updatedCatalogueInfo.LastUpdateDateTime = pLastUpdate.Value;
                needsToSave = true;
            }

            if (!string.IsNullOrEmpty(pVersion = pVersion?.Trim()) && (newCatalogue || (pVersion != updatedCatalogueInfo.Version)))
            {
                updatedCatalogueInfo.Version = pVersion;
                needsToSave = true;
            }


            if (!needsToSave)
            {
                return(index);
            }

            if (newCatalogue)
            {
                Catalogues.Add(updatedCatalogueInfo);
            }
            else
            {
                Catalogues[index] = updatedCatalogueInfo;
            }

            List <CatalogueInfo> catalogues = Catalogues.OrderBy(o => o.Name).ToList();

            Catalogues = catalogues;

            string errorText;

            if (pAutoSave)
            {
                Save(CataloguesIndexFilePath, out errorText);
            }

            return(GetIndexByName(pName));
        }