void InstallationStep5(string downloadPath, EffectPackage package) { UpdateStatus("Working on " + targetName + " ...", "Extracting " + package.PackageName + " ..."); string tempPath = Path.Combine(Path.GetTempPath(), "reshade-shaders"); try { if (Directory.Exists(tempPath)) // Delete existing directories since extraction fails if the target is not empty { Directory.Delete(tempPath, true); } ZipFile.ExtractToDirectory(downloadPath, tempPath); // First check for a standard folder name string tempPathShaders = Directory.GetDirectories(tempPath, "Shaders", SearchOption.AllDirectories).FirstOrDefault(); string tempPathTextures = Directory.GetDirectories(tempPath, "Textures", SearchOption.AllDirectories).FirstOrDefault(); // If that does not exist, look for the first directory that contains shaders/textures if (tempPathShaders == null) { tempPathShaders = Directory.GetFiles(tempPath, "*.fx", SearchOption.AllDirectories).Select(x => Path.GetDirectoryName(x)).OrderBy(x => x.Length).FirstOrDefault(); } if (tempPathTextures == null) { string[] tempTextureExtensions = { "*.png", "*.jpg", "*.jpeg" }; foreach (string extension in tempTextureExtensions) { tempPathTextures = tempPathTextures.Union(Directory.GetFiles(tempPath, extension, SearchOption.AllDirectories).Select(x => Path.GetDirectoryName(x)).OrderBy(x => x.Length).FirstOrDefault()).ToString(); } } // Move only the relevant files to the target if (tempPathShaders != null) { MoveFiles(tempPathShaders, Path.Combine(Path.GetDirectoryName(targetPath), package.InstallPath)); } if (tempPathTextures != null) { MoveFiles(tempPathTextures, Path.Combine(Path.GetDirectoryName(targetPath), package.TextureInstallPath)); } File.Delete(downloadPath); Directory.Delete(tempPath, true); } catch (Exception ex) { UpdateStatusAndFinish(false, "Failed to extract " + package.PackageName + ".", ex.Message); return; } WriteSearchPaths(package.InstallPath, package.TextureInstallPath); InstallationStep6(); }
void InstallationStep5(string downloadPath, EffectPackage package) { UpdateStatus("Working on " + targetName + " ...", "Extracting " + package.PackageName + " ..."); string tempPath = Path.Combine(Path.GetTempPath(), "reshade-shaders"); try { // Delete existing directories since extraction fails if the target is not empty if (Directory.Exists(tempPath)) { Directory.Delete(tempPath, true); } ZipFile.ExtractToDirectory(downloadPath, tempPath); // First check for a standard directory name string tempPathShaders = Directory.GetDirectories(tempPath, "Shaders", SearchOption.AllDirectories).FirstOrDefault(); string tempPathTextures = Directory.GetDirectories(tempPath, "Textures", SearchOption.AllDirectories).FirstOrDefault(); string targetPathShaders = Path.Combine(Path.GetDirectoryName(targetPath), package.InstallPath); string targetPathTextures = Path.Combine(Path.GetDirectoryName(targetPath), package.TextureInstallPath); // If that does not exist, look for the first directory that contains shaders/textures string[] effects = Directory.GetFiles(tempPath, "*.fx", SearchOption.AllDirectories); if (tempPathShaders == null) { tempPathShaders = effects.Select(x => Path.GetDirectoryName(x)).OrderBy(x => x.Length).FirstOrDefault(); } if (tempPathTextures == null) { string[] tempTextureExtensions = { "*.png", "*.jpg", "*.jpeg" }; foreach (string extension in tempTextureExtensions) { string path = Directory.GetFiles(tempPath, extension, SearchOption.AllDirectories).Select(x => Path.GetDirectoryName(x)).OrderBy(x => x.Length).FirstOrDefault(); tempPathTextures = tempPathTextures != null?tempPathTextures.Union(path).ToString() : path; } } // Show file selection dialog if (!isHeadless && package.Enabled == null) { effects = effects.Select(x => targetPathShaders + x.Remove(0, tempPathShaders.Length)).ToArray(); var dlg = new SelectEffectsDialog(package.PackageName, effects); dlg.Owner = this; if (dlg.ShowDialog() == true) { // Delete all unselected effect files before moving foreach (string filePath in effects.Except(dlg.EnabledItems.Select(x => x.FilePath))) { File.Delete(tempPathShaders + filePath.Remove(0, targetPathShaders.Length)); } } } // Move only the relevant files to the target if (tempPathShaders != null) { MoveFiles(tempPathShaders, targetPathShaders); } if (tempPathTextures != null) { MoveFiles(tempPathTextures, targetPathTextures); } File.Delete(downloadPath); Directory.Delete(tempPath, true); } catch (Exception ex) { UpdateStatusAndFinish(false, "Failed to extract " + package.PackageName + ".", ex.Message); return; } WriteSearchPaths(package.InstallPath, package.TextureInstallPath); InstallationStep6(); }