Beispiel #1
0
        private bool CheckEntity(ProcessingFlags pProcessingFlags, out string pReport)
        {
            pReport = null;

            bool reportOnlyIssues = pProcessingFlags.HasFlag(ProcessingFlags.JustReportIssues);
            // bool showAddonContents = pProcessingFlags.HasFlag(ProcessingFlags.ShowAddonContents);


            DirectoryInfo directoryInfo = new DirectoryInfo(EntityPath);

            FileInfo[] addonInfoList = directoryInfo.GetFiles("*.addon", SearchOption.TopDirectoryOnly);

            foreach (FileInfo item in addonInfoList)
            {
                new DiskEntityAddon(item.FullName, ArchivedPath, ReportWriter).CheckEntity(pProcessingFlags);
            }


            FileInfo[] sketchupInfoList = directoryInfo.GetFiles("*.skp", SearchOption.TopDirectoryOnly);

            foreach (FileInfo item in sketchupInfoList)
            {
                new DiskEntitySketchup(item.FullName, null, ReportWriter).CheckEntity(pProcessingFlags);
            }


            FileInfo[] archiveInfoList = directoryInfo.GetFiles("*.zip", SearchOption.TopDirectoryOnly);
            FileInfo[] rarInfoList     = directoryInfo.GetFiles("*.rar", SearchOption.TopDirectoryOnly);
            archiveInfoList = archiveInfoList.Concat(rarInfoList).ToArray();
            FileInfo[] s7InfoList = directoryInfo.GetFiles("*.7z", SearchOption.TopDirectoryOnly);
            archiveInfoList = archiveInfoList.Concat(s7InfoList).ToArray();

            foreach (FileInfo item in archiveInfoList)
            {
                new DiskEntityArchive(item.FullName, ArchivedPath, ReportWriter).CheckEntity(pProcessingFlags);
            }


            if (!pProcessingFlags.HasFlag(ProcessingFlags.FolderTopOnlySearch))
            {
                DirectoryInfo[] subdirectories = directoryInfo.GetDirectories();
                if (subdirectories.Length > 0)
                {
                    foreach (DirectoryInfo subdirectoryInfo in subdirectories)
                    {
                        new DiskEntityFolder(subdirectoryInfo.FullName, null, ReportWriter).CheckEntity(pProcessingFlags);
                    }
                }
            }

            return(true);
        }
Beispiel #2
0
        private bool CheckEntity(ProcessingFlags pProcessingFlags, out string pReport)
        {
            bool reportOnlyIssues = pProcessingFlags.HasFlag(ProcessingFlags.JustReportIssues);
            // bool showAddonContents = pProcessingFlags.HasFlag(ProcessingFlags.ShowAddonContents);
            string versionString = null;

            try
            {
                byte[] headerBytes = File.ReadAllBytes(AbsolutePath);

                versionString = GetVersionString(headerBytes);
                if (versionString == null)
                {
                    pReport = $"{ErrorTokenString} Invalid file/unknown format";
                    return(false);
                }

                if (!versionString.StartsWith("6."))
                {
                    pReport = $"{ErrorTokenString} Format not importable [{versionString}]";
                    return(false);
                }
            }
            catch
            {
            }


            pReport = $"OK [{versionString}]";

            return(true);
        }
Beispiel #3
0
        private bool CheckEntity(ProcessingFlags pProcessingFlags, out string pReport)
        {
            pReport = null;
            bool showDetailedContents = pProcessingFlags.HasFlag(ProcessingFlags.ShowAddonContents);
            bool appendToPackageSet   = pProcessingFlags.HasFlag(ProcessingFlags.AppendToAddonPackageSet);

            if (!showDetailedContents)
            {
                pReport = BriefReport();

                if (!appendToPackageSet)
                {
                    return(true);
                }
            }

            string tempPath = Utils.GetTempDirectory();

            AddonPackage package = new AddonPackage(AbsolutePath, pProcessingFlags, tempPath);

            if (showDetailedContents)
            {
                pReport = package?.ToString();
            }

            if (appendToPackageSet && (AddonPackageSet != null) && (package != null))
            {
                if (package.HasIssues)
                {
                    pReport += " >>> NOT inserted/updated into Catalogue (has problems!)";
                }
                else
                {
                    if (AddonPackageSet.Append(package, pProcessingFlags.HasFlag(ProcessingFlags.AppendToAddonPackageSetForceRefresh)))
                    {
                        pReport += " >>> Inserted/updated into Catalogue";
                    }
                }
            }

            return(true);
        }
Beispiel #4
0
        // ---------------------------------------------------------------------------------------------------------------

        public bool CheckEntity(ProcessingFlags pProcessingFlags, string pNamePrinted = null)
        {
            string report;
            bool   checkOk = CheckEntity(pProcessingFlags, out report);

            if (checkOk && pProcessingFlags.HasFlag(ProcessingFlags.JustReportIssues))
            {
                return(false);
            }

            ReportWriter.WriteReportLineFeed($"{Name} : {report}");
            return(checkOk);
        }
Beispiel #5
0
        // ---------------------------------------------------------------------------

        // TODO - Print report
        public bool CheckEntity(ProcessingFlags pProcessingFlags, string pNamePrinted = null)
        {
            string report;
            bool   checkOk = CheckEntity(pProcessingFlags, out report);

            pNamePrinted = string.IsNullOrEmpty(pNamePrinted) ? Name : Name + pNamePrinted;

            if (checkOk && pProcessingFlags.HasFlag(ProcessingFlags.JustReportIssues))
            {
                return(false);
            }

            if (!checkOk || !pProcessingFlags.HasFlag(ProcessingFlags.ShowAddonContents))
            {
                ReportWriter.WriteReportLineFeed($"*{pNamePrinted} : {report}");
                return(checkOk);
            }

            ReportWriter.WriteReportLineFeed($"*{pNamePrinted} :");
            // ReportWriter.IncreaseReportLevel();
            ReportWriter.WriteReportLineFeed(report);
            // ReportWriter.DecreaseReportLevel();
            return(true);
        }
Beispiel #6
0
        /// <summary>
        /// Checks files inside the archive
        /// </summary>
        /// <param name="pProcessingFlags">Processing flags</param>
        /// <param name="pArchiver">Archiver used to manage the archive contents</param>
        /// <param name="pArchiveEntryList">Full information about files in archive</param>
        /// <param name="pFileList">List of files inside the archive</param>
        /// <param name="pReport">Output text</param>
        /// <returns>Result of check</returns>
        private bool CheckFiles(ProcessingFlags pProcessingFlags, SevenZipArchiver pArchiver, List <ArchiveFileInfo> pArchiveEntryList, List <string> pFileList, out string pReport)
        {
            // bool reportOnlyIssues = pProcessingFlags.HasFlag(ProcessingFlags.JustReportIssues);
            // bool showAddonContents = pProcessingFlags.HasFlag(ProcessingFlags.ShowAddonContents);


            string rootTempPath = Utils.GetTempDirectory();

            pArchiver.ArchivedFilesExtract(rootTempPath, pFileList);
            string currentPath = Utils.GetExecutableDirectory();

            Directory.SetCurrentDirectory(rootTempPath);
            pReport = null;
            try
            {
                foreach (string fileName in pFileList)
                {
                    string extension =
                        Path.GetExtension(fileName)?.Trim().ToLower();

                    bool isAddonFile = false;
                    if (extension == ".addon")
                    {
                        if (fileName.ToLower() == ".addon")
                        {
                            string rootFolder;
                            if (!InsideArchive && pProcessingFlags.HasFlag(ProcessingFlags.CorrectDisguisedFiles) &&
                                IsValidAddon(pArchiveEntryList, false, out rootFolder))
                            {
                                string errorText;
                                string newAddonFile = AddonPersistenceUtils.CorrectAddonFile(pArchiver, pProcessingFlags.HasFlag(ProcessingFlags.CorrectDisguisedFilesDeleteSource), null, out errorText);
                                if (newAddonFile == null)
                                {
                                    pReport = $"   {ErrorTokenString} Possibly an Addon file disguised as an archive. Failed to restore: {errorText}";
                                    return(false);
                                }
                                pReport = $"   Addon file disguised as an archive. Restored: {Path.GetFileName(newAddonFile)}";
                                return(true);
                            }
                            else
                            {
                                pReport = $"   {ErrorTokenString} Possibly an Addon file disguised as an archive";
                                return(false);
                            }
                        }
                        if (fileName.ToLower().EndsWith(@"\.addon"))
                        {
                            string rootFolder;
                            if (!InsideArchive && pProcessingFlags.HasFlag(ProcessingFlags.CorrectDisguisedFiles) &&
                                IsValidAddon(pArchiveEntryList, true, out rootFolder))
                            {
                                string errorText;
                                string newAddonFile = AddonPersistenceUtils.CorrectAddonFile(pArchiver, pProcessingFlags.HasFlag(ProcessingFlags.CorrectDisguisedFilesDeleteSource), rootFolder, out errorText);
                                if (newAddonFile == null)
                                {
                                    pReport = $"   {ErrorTokenString} Possibly an Addon file disguised as an archive. Failed to restore: {errorText}";
                                    return(false);
                                }
                                pReport = $"   Addon file disguised as an archive. Restored: {Path.GetFileName(newAddonFile)}";
                                return(true);
                            }
                            else
                            {
                                pReport =
                                    $"   {ErrorTokenString} Possibly an Addon file disguised as an archive, with a root directory";
                                return(false);
                            }
                        }

                        isAddonFile = true;
                    }

                    string archivedPath = $"{AbsolutePath}#{fileName}";

                    IDiskEntity diskEntity =
                        isAddonFile
                        ? new DiskEntityAddon(fileName, archivedPath, ReportWriter)
                        : (IDiskEntity) new DiskEntitySketchup(fileName, archivedPath, ReportWriter);

                    diskEntity.CheckEntity(pProcessingFlags);

                    File.Delete(fileName);
                }
            }
            catch
            {
            }
            finally
            {
                Directory.SetCurrentDirectory(currentPath);
            }

            return(true);
        }
Beispiel #7
0
        private bool CheckEntity(ProcessingFlags pProcessingFlags, out string pReport)
        {
            bool reportOnlyIssues   = pProcessingFlags.HasFlag(ProcessingFlags.JustReportIssues);
            bool showAddonContents  = pProcessingFlags.HasFlag(ProcessingFlags.ShowAddonContents);
            bool appendToPackageSet = pProcessingFlags.HasFlag(ProcessingFlags.AppendToAddonPackageSet);
            List <ArchiveFileInfo> entryList;

            SevenZipArchiver archiver = new SevenZipArchiver(AbsolutePath);

            archiver.ArchivedFileList(out entryList);
            if ((entryList?.Count ?? -1) <= 0)
            {
                pReport = $"{ErrorTokenString} Invalid file or format";
                if (showAddonContents)
                {
                    pReport += "\n";
                }
                return(false);
            }

            List <string>      demoMovies, stockAssets;
            bool               hasMeshes, hasData;
            AddonSignatureFile addonSignature;
            bool               formatOk = CheckFormat(archiver, entryList, out hasMeshes, out hasData, out demoMovies, out stockAssets, out addonSignature);

            if (!formatOk)
            {
                pReport = $"{ErrorTokenString} Invalid/obsolete addon format";
                if (showAddonContents)
                {
                    pReport += "\n";
                }
                return(false);
            }

            // Addon good format

            pReport = null;
            if (reportOnlyIssues)
            {
                return(true);
            }

            if (!showAddonContents)
            {
                pReport = (hasMeshes ? "OK" : "OK, no meshes");
                if (demoMovies != null)
                {
                    pReport += " (incl. Movies)";
                }
                if (stockAssets != null)
                {
                    pReport += " (incl. Stock assets)";
                }
                string freeText = addonSignature.Free ? "" : "  NOT FREE!";
                pReport += $"   [{addonSignature.Publisher}{freeText}]";
                if (!appendToPackageSet)
                {
                    return(true);
                }
            }

            string tempPath = Utils.GetTempDirectory();


            AddonPackage package = new AddonPackage(archiver, pProcessingFlags, tempPath, ArchivedPath);

            if (showAddonContents)
            {
                pReport = package?.ToString();
            }

            if (appendToPackageSet && (AddonPackageSet != null) && (package != null))
            {
                if (package.HasIssues)
                {
                    pReport += " >>> Not inserted/updated into Catalogue (has problems!)";
                }
                else
                {
                    if (AddonPackageSet.Append(package, pProcessingFlags.HasFlag(ProcessingFlags.AppendToAddonPackageSetForceRefresh)))
                    {
                        pReport += " >>> Inserted/updated into Catalogue";
                    }
                }
            }


            return(true);
        }