public static bool xmlDB_Libraries_ImportFromZip(this TM_Xml_Database tmDatabase, string zipFileToImport, string unzipPassword) { var result = false; try { var currentLibraryPath = tmDatabase.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) { tmDatabase.reloadGuidanceExplorerObjects(); } return(result); }
public static string xmlDB_DeleteGuidanceExplorer(this TM_Xml_Database tmDatabase, Guid libraryId) { var tmLibrary = tmDatabase.tmLibrary(libraryId); if (tmLibrary.notNull()) { var caption = tmLibrary.Caption; if (caption.isValidGuidanceExplorerName()) { "[xmlDB_DeleteGuidanceExplorer] deleting library with caption: {0}".info(caption); var pathToLibrary = tmDatabase.xmlDB_LibraryPath(caption); var pathToGuidanceItemsFolder = tmDatabase.xmlDB_LibraryPath_GuidanceItems(caption); if (pathToGuidanceItemsFolder.dirExists()) { "[xmlDB_DeleteGuidanceExplorer] deleting library guidanceItems folder: {0}".debug(pathToGuidanceItemsFolder); if (Files.deleteFolder(pathToGuidanceItemsFolder, true).isFalse()) { "[xmlDB_DeleteGuidanceExplorer] there was an error deleting the folder: {0}".error(pathToGuidanceItemsFolder); return(null); } } "[xmlDB_DeleteGuidanceExplorer] deleting library guidanceItems file: {0}".debug(pathToLibrary); Files.deleteFile(pathToLibrary); if (pathToLibrary.fileExists()) { "[xmlDB_DeleteGuidanceExplorer] there was problem deleting the file: {0}".error(pathToLibrary); } //check if there is a root directory with the caption name (happens when imported from ZIP pathToGuidanceItemsFolder = tmDatabase.xmlDB_LibraryPath_GuidanceItems(caption); if (pathToGuidanceItemsFolder.dirExists() && pathToGuidanceItemsFolder.files().size() == 0) { Files.deleteFolder(pathToGuidanceItemsFolder); } //finally reset these tmDatabase.reloadGuidanceExplorerObjects(); //reset these } } return(null); }
public static bool xmlDB_DeleteGuidanceExplorer(this TM_Xml_Database tmDatabase, Guid libraryId) { var tmLibrary = tmDatabase.tmLibrary(libraryId); if (tmLibrary.isNull()) { return(false); } if (tmDatabase.UsingFileStorage) { "[xmlDB_DeleteGuidanceExplorer] deleting library with caption: {0}".info(tmLibrary.Caption); var pathToLibraryFolder = tmDatabase.xmlDB_Path_Library_RootFolder(tmLibrary); // this is also the Library Root if (pathToLibraryFolder.notValid() || pathToLibraryFolder == tmDatabase.Path_XmlDatabase || pathToLibraryFolder == tmDatabase.Path_XmlLibraries) { "[xmlDB_DeleteGuidanceExplorer] [Stopping delete] Something is wrong with the pathToLibrary to delete : {0}" .error(pathToLibraryFolder); return(false); } if (pathToLibraryFolder.contains(tmDatabase.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); tmDatabase.reloadGuidanceExplorerObjects(); //reset these } else { TM_Xml_Database.Current.GuidanceExplorers_XmlFormat.remove(tmLibrary.Id); } return(true); }
public static bool xmlDB_Libraries_ImportFromZip(this TM_Xml_Database tmDatabase, string zipFileToImport, string unzipPassword) { var result = false; try { var currentLibraryPath = tmDatabase.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); //zipFileToImport = zipFileToImport.uri().download(); } "[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 result = true; /* * var gitZipFolderName = tempDir.folders().first().folderName(); // the first folder should be the one created by gitHub's zip * var xmlFile_Location1 = tempDir.pathCombine(gitZipFolderName + ".xml"); * var xmlFile_Location2 = tempDir.pathCombine(gitZipFolderName).pathCombine(gitZipFolderName + ".xml"); * if (xmlFile_Location1.fileExists() || xmlFile_Location2.fileExists()) * // if these exists here, just copy the unziped files directly * { * Files.copyFolder(tempDir, currentLibraryPath, true, true, ".git"); * if (xmlFile_Location1.fileExists()) * Files.copy(xmlFile_Location1, currentLibraryPath.pathCombine(gitZipFolderName)); * result = true; * } * else * { * //if (zipFileToImport.extension() == ".master") * var gitZipDir = tempDir.pathCombine(gitZipFolderName); * foreach (var libraryFolder in gitZipDir.folders()) * { * var libraryName = libraryFolder.folderName(); * var targetFolder = currentLibraryPath.pathCombine(libraryName); * * //default behaviour is to override the existing libraries * Files.copyFolder(libraryFolder, currentLibraryPath); * * //handle the case where the xml file is located outside the library folder * var libraryXmlFile = gitZipDir.pathCombine("{0}.xml".format(libraryName)); * if (libraryXmlFile.fileExists()) * Files.copy(libraryXmlFile, targetFolder); * // put it in the Library folder which is where it really should be * } * var virtualMappings = gitZipDir.pathCombine("Virtual_Articles.xml"); * if (virtualMappings.fileExists()) * { * Files.copy(virtualMappings, currentLibraryPath); // copy virtual mappings if it exists * tmDatabase.mapVirtualArticles(); * } * result = true; * } */ } } catch (Exception ex) { ex.log("[xmlDB_Libraries_ImportFromZip]"); } if (result) { tmDatabase.reloadGuidanceExplorerObjects(); } //tmDatabase.loadLibraryDataFromDisk(); return(result); }