示例#1
0
        public static bool library_Deleted(this TM_FileStorage tmFileStorage, TM_Library tmLibrary)
        {
            "[xmlDB_DeleteGuidanceExplorer] deleting library with caption: {0}".info(tmLibrary.Caption);
            var pathToLibraryFolder = tmFileStorage.xmlDB_Path_Library_RootFolder(tmLibrary);

            // this is also the Library Root
            if (pathToLibraryFolder.notValid() || pathToLibraryFolder == tmFileStorage.path_XmlDatabase() ||
                pathToLibraryFolder == tmFileStorage.Path_XmlLibraries)
            {
                "[xmlDB_DeleteGuidanceExplorer] [Stopping delete] Something is wrong with the pathToLibrary to delete : {0}"
                .error(pathToLibraryFolder);
                return(false);
            }
            if (pathToLibraryFolder.contains(tmFileStorage.Path_XmlLibraries).isFalse())
            {
                "[xmlDB_DeleteGuidanceExplorer] [Stopping delete] the  pathToLibrary should contain tmDatabase.Path_XmlLibraries : {0}"
                .error(pathToLibraryFolder);
                return(false);
            }
            // the checks above are important since the line below is a recursive folder delete (which can delete a LOT of content is pointed to the wrong folder)
            if (Files.deleteFolder(pathToLibraryFolder, true).isFalse())
            {
                "[xmlDB_DeleteGuidanceExplorer] there was an error deleting the folder: {0}".error(
                    pathToLibraryFolder);
                return(false);
            }

            "[xmlDB_DeleteGuidanceExplorer] Library folder deleted OK: {0}".info(pathToLibraryFolder);
            tmFileStorage.reloadGuidanceExplorerObjects(); //reset these

            return(true);
        }
示例#2
0
        public static bool xmlDB_Libraries_ImportFromZip(this TM_FileStorage tmFileStorage, string zipFileToImport, string unzipPassword)
        {
            UserRole.Admin.demand();

            var result = false;

            try
            {
                var currentLibraryPath = tmFileStorage.Path_XmlLibraries;
                if (currentLibraryPath.isNull())
                {
                    return(false);
                }
                if (zipFileToImport.isUri())
                {
                    "[xmlDB_Libraries_ImportFromZip] provided value was an URL so, downloading it: {0}".info(zipFileToImport);
                    zipFileToImport = new Web().downloadBinaryFile(zipFileToImport);
                }
                "[xmlDB_Libraries_ImportFromZip] importing library from: {0}".info(zipFileToImport);
                if (zipFileToImport.fileExists().isFalse())
                {
                    "[xmlDB_Libraries_ImportFromZip] could not find file to import".error(zipFileToImport);
                }
                else
                {
                    // handle the zips we get from GitHub

                    var tempDir = @"..\_".add_RandomLetters(3).tempDir(false).fullPath(); //trying to make the unzip path as small as possible
                    var fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip {
                        Password = unzipPassword ?? ""
                    };

                    fastZip.ExtractZip(zipFileToImport, tempDir, "");

                    Files.copyFolder(tempDir, currentLibraryPath, true, true, "");          // just copy all files into Library path
                    Files.deleteFolder(tempDir, true);                                      // delete tmp folder created
                    result = true;
                }
            }
            catch (Exception ex)
            {
                ex.log("[xmlDB_Libraries_ImportFromZip]");
            }

            if (result)
            {
                tmFileStorage.reloadGuidanceExplorerObjects();
            }

            return(result);
        }