Beispiel #1
0
        /// <summary>
        /// Finds and returns the path to the database file in a directory.
        /// Returns "" if no file is found.
        /// </summary>
        /// <param name="directoryPath">The path to the directory that this method will check.</param>
        /// <returns></returns>
        public string GetDatabaseFileInDirectory(string directoryPath)
        {
            FileExtensionFactory factory = new FileExtensionFactory();
            DirectoryInfo directoryInfo = new DirectoryInfo(directoryPath);
            FileInfo[] fileInfo = directoryInfo.GetFiles();
            string extension = factory.GetFileExtension(FileTypeEnum.Database);
            string databaseFilePath = "";

            foreach (FileInfo file in fileInfo)
            {
                if (file.Extension == extension)
                {
                    databaseFilePath = file.FullName;
                    break;
                }
            }

            return databaseFilePath;
        }
Beispiel #2
0
        /// <summary>
        /// Checks the ContentPackages directory for the required content packs that the module uses.
        /// If any of them are missing, a pop-up window will display and this method will return false.
        /// </summary>
        /// <returns></returns>
        public bool CheckForMissingContentPackages()
        {
            List<string> missingContentPackages;
            List<string> fileContentPackages = new List<string>();
            List<string> moduleContentPackages;

            // Retrieve the existing content packages (ones which are in the ContentPackages directory)
            FileExtensionFactory factory = new FileExtensionFactory();
            string[] filePaths = Directory.GetFiles(DirectoryPaths.ContentPackageDirectoryPath, "*" + factory.GetFileExtension(FileTypeEnum.ContentPackage));
            foreach (string path in filePaths)
            {
                fileContentPackages.Add(Path.GetFileName(path));
            }

            // Retrieve the required content packages (ones which are attached to the module)
            using (ContentPackageRepository repo = new ContentPackageRepository())
            {
                IEnumerable<ContentPackage> contentPackages = repo.GetAll();
                moduleContentPackages = (from package
                                         in contentPackages
                                         select package.FileName).ToList();
            }

            // Determine which content packages do not exist on disk that are required by this module.
            missingContentPackages = moduleContentPackages.Except(fileContentPackages).ToList();

            if (missingContentPackages.Count > 0)
            {
                string errorMessage = "Unable to locate the following content packages:\n\n";

                foreach (string current in missingContentPackages)
                {
                    errorMessage += current + "\n";
                }

                errorMessage += "\nPlease place the missing content packages in the ContentPacks folder and try again.";

                MessageBox.Show(errorMessage, "Missing Content Packages", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }
            else
            {
                return true;
            }
        }