public ModuleInfo ReadModuleInfo(string moduleFilePath) { string destFolder = Path.Combine(GetTempFolderPath(), Path.GetFileNameWithoutExtension(moduleFilePath)); try { if (Directory.Exists(destFolder)) { Directory.Delete(destFolder, true); } Directory.CreateDirectory(destFolder); ZipLibHelper.ExtractZipFile(File.ReadAllBytes(moduleFilePath), destFolder, new string[] { SystemConstants.ManifestFileName }); string manifestFilePath = Path.Combine(destFolder, SystemConstants.ManifestFileName); if (!File.Exists(manifestFilePath)) { throw new InvalidModuleException($"File '{manifestFilePath}' not found."); } return(Dessirialize <ModuleInfo>(manifestFilePath)); } finally { ThreadPool.QueueUserWorkItem(DeleteDirectory, destFolder); } }
public ModuleInfo UploadModule(string originalFilePath, string moduleName) { if (Path.GetExtension(originalFilePath).ToLower() != SystemConstants.ModuleFileExtension) { throw new InvalidModuleException($"Please select a file with extension '{SystemConstants.ModuleFileExtension}'."); } var destFilePath = Path.Combine(GetModulesPackagesDirectory(), moduleName + SystemConstants.ModuleFileExtension); destFilePath = CopyModulePackage(originalFilePath, destFilePath); string destFolder = GetModuleDirectory(moduleName); if (Directory.Exists(destFolder)) { Directory.Delete(destFolder, true); } Directory.CreateDirectory(destFolder); try { ZipLibHelper.ExtractZipFile(File.ReadAllBytes(destFilePath), destFolder); var module = GetModuleInfo(moduleName); CheckModule(module); if (module.Type == Scheme.Module.ModuleType.Bible || module.Type == Scheme.Module.ModuleType.Strong) { var baseModule = GetModuleInfo(_configurationManager.ModuleShortName); if (_bibleParallelTranslationManager.MergeModuleWithMainBible(baseModule, module)) { UpdateModuleManifest(baseModule); } else { _bibleParallelTranslationManager.MergeAllModulesWithMainBible(baseModule, GetModules(true).Where(m => m.ShortName != _configurationManager.ModuleShortName)); } } return(module); } catch (Exception ex) { throw new InvalidModuleException(ex.Message); } }