using System.IO; using System.IO.Compression; namespace Flow.Launcher.Plugin.PluginsManager { internal static class Utilities { /// /// Unzip contents to the given directory. /// /// The path to the zip file. /// The output directory. /// overwrite internal static void UnZip(string zipFilePath, string strDirectory, bool overwrite) { ZipFile.ExtractToDirectory(zipFilePath, strDirectory, overwrite); } internal static string GetContainingFolderPathAfterUnzip(string unzippedParentFolderPath) { var unzippedFolderCount = Directory.GetDirectories(unzippedParentFolderPath).Length; var unzippedFilesCount = Directory.GetFiles(unzippedParentFolderPath).Length; // adjust path depending on how the plugin is zipped up // the recommended should be to zip up the folder not the contents if (unzippedFolderCount == 1 && unzippedFilesCount == 0) // folder is zipped up, unzipped plugin directory structure: tempPath/unzippedParentPluginFolder/pluginFolderName/ return Directory.GetDirectories(unzippedParentFolderPath)[0]; if (unzippedFilesCount > 1) // content is zipped up, unzipped plugin directory structure: tempPath/unzippedParentPluginFolder/ return unzippedParentFolderPath; return string.Empty; } } }