|
|
1.1 root 1: using CleanFlashCommon;
2: using System;
3: using System.Collections.Generic;
4: using System.IO;
5: using System.Reflection;
6: using System.Diagnostics;
7: using SharpCompress.Archives.SevenZip;
8: using SharpCompress.Common;
9: using SharpCompress.Readers;
10: using IWshRuntimeLibrary;
11:
12: namespace CleanFlashInstaller {
13: public class Installer {
14: public static void RegisterActiveX(string filename) {
15: Directory.SetCurrentDirectory(Path.GetDirectoryName(filename));
16: ExitedProcess process = ProcessRunner.RunProcess(
17: new ProcessStartInfo {
18: FileName = "regsvr32.exe",
19: Arguments = "/s " + Path.GetFileName(filename),
20: UseShellExecute = false,
21: CreateNoWindow = true
22: }
23: );
24:
25: if (!process.IsSuccessful) {
26: throw new InstallException(string.Format("Failed to register ActiveX plugin: error code {0}\n\n{1}", process.ExitCode, process.Output));
27: }
28: }
29:
30: public static void ExtractArchive(SevenZipArchive archive, Dictionary<string, InstallEntry> entries, IProgressForm form, InstallFlags flags) {
31: IReader reader = archive.ExtractAllEntries();
32: bool legacy = SystemInfo.IsLegacyWindows();
33: string lastKey = null;
34:
35: while (reader.MoveToNextEntry()) {
36: if (reader.Entry.IsDirectory) {
37: continue;
38: }
39:
40: string filename = reader.Entry.Key.Split('/')[0];
41: string installKey = filename.Split('-')[0];
42: InstallEntry installEntry = entries[installKey];
43:
44: if (installEntry.RequiredFlags.GetValue() != InstallFlags.NONE) {
45: if (!flags.IsSet(installEntry.RequiredFlags)) {
46: continue;
47: }
48:
49: if (flags.IsSet(InstallFlags.DEBUG) != filename.Contains("-debug")) {
50: continue;
51: }
52: }
53:
54: if (installEntry.RequiredFlags.IsSet(InstallFlags.ACTIVEX)) {
55: if (legacy != filename.Contains("-legacy")) {
56: continue;
57: }
58: }
59:
60: if (!installKey.Equals(lastKey)) {
61: form.UpdateProgressLabel(installEntry.InstallText, true);
62:
63: if (!Directory.Exists(installEntry.TargetDirectory)) {
64: Directory.CreateDirectory(installEntry.TargetDirectory);
65: }
66:
67: lastKey = installKey;
68: }
69:
70: reader.WriteEntryToDirectory(installEntry.TargetDirectory, new ExtractionOptions() {
71: ExtractFullPath = false,
72: Overwrite = true
73: });
74: }
75: }
76:
77: public static void CreateShortcut(string folder, string executable, string name, string description) {
78: WshShell wsh = new WshShell();
79: IWshShortcut shortcut = wsh.CreateShortcut(Path.Combine(folder, name + ".lnk")) as IWshShortcut;
80:
81: shortcut.Arguments = "";
82: shortcut.TargetPath = executable;
83: shortcut.WindowStyle = (int) WshWindowStyle.WshNormalFocus;
84: shortcut.Description = description;
85: shortcut.WorkingDirectory = Path.GetDirectoryName(executable);
86: shortcut.IconLocation = executable;
87: shortcut.Save();
88: }
89:
90: private static void InstallFromArchive(SevenZipArchive archive, IProgressForm form, InstallFlags flags) {
91: string flash32Path = SystemInfo.GetFlash32Path();
92: string flash64Path = SystemInfo.GetFlash64Path();
93: string system32Path = SystemInfo.GetSystem32Path();
94: string flashProgram32Path = SystemInfo.GetProgramFlash32Path();
95: List<string> registryToApply = new List<string>() { Properties.Resources.installGeneral };
96:
97: if (Environment.Is64BitOperatingSystem) {
98: flags.SetFlag(InstallFlags.X64);
99: registryToApply.Add(Properties.Resources.installGeneral64);
100: }
101:
102: Dictionary<string, InstallEntry> entries = new Dictionary<string, InstallEntry>() {
103: { "controlpanel", new InstallEntry("Installing Flash Player utilities...", InstallFlags.NONE, system32Path) },
104: { "uninstaller", new InstallEntry("Extracting uninstaller...", InstallFlags.NONE, flashProgram32Path) },
105: { "standalone", new InstallEntry("Installing 32-bit Standalone Flash Player...", InstallFlags.PLAYER, flashProgram32Path) },
106: { "ocx32", new InstallEntry("Installing 32-bit Flash Player for Internet Explorer...", InstallFlags.ACTIVEX, flash32Path) },
107: { "np32", new InstallEntry("Installing 32-bit Flash Player for Firefox...", InstallFlags.NETSCAPE, flash32Path, Properties.Resources.installNP) },
108: { "pp32", new InstallEntry("Installing 32-bit Flash Player for Chrome...", InstallFlags.PEPPER, flash32Path, Properties.Resources.installPP) },
109: { "ocx64", new InstallEntry("Installing 64-bit Flash Player for Internet Explorer...", InstallFlags.ACTIVEX | InstallFlags.X64, flash64Path) },
110: { "np64", new InstallEntry("Installing 64-bit Flash Player for Firefox...", InstallFlags.NETSCAPE | InstallFlags.X64, flash64Path, Properties.Resources.installNP64) },
111: { "pp64", new InstallEntry("Installing 64-bit Flash Player for Chrome...", InstallFlags.PEPPER | InstallFlags.X64, flash64Path, Properties.Resources.installPP64) },
112: };
113:
114: ExtractArchive(archive, entries, form, flags);
115:
116: if (flags.IsSet(InstallFlags.PLAYER)) {
117: bool debug = flags.IsSet(InstallFlags.DEBUG);
118: string name = "Flash Player";
119: string description = "Standalone Flash Player " + UpdateChecker.GetFlashVersion();
120: string executable = Path.Combine(flashProgram32Path, debug ? "flashplayer_sa_debug.exe" : "flashplayer_sa.exe");
121:
122: if (debug) {
123: name += " (Debug)";
124: description += " (Debug)";
125: }
126:
127: if (flags.IsSet(InstallFlags.PLAYER_START_MENU)) {
128: CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu), executable, name, description);
129: }
130:
131: if (flags.IsSet(InstallFlags.PLAYER_DESKTOP)) {
132: CreateShortcut(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), executable, name, description);
133: }
134: }
135:
136: foreach (InstallEntry entry in entries.Values) {
137: if (flags.IsSet(entry.RequiredFlags) && entry.RegistryInstructions != null) {
138: registryToApply.Add(entry.RegistryInstructions);
139: }
140: }
141:
142: form.UpdateProgressLabel("Applying registry changes...", true);
143: RegistryManager.ApplyRegistry(registryToApply);
144:
145: if (flags.IsSet(InstallFlags.ACTIVEX)) {
146: form.UpdateProgressLabel("Activating 32-bit Flash Player for Internet Explorer...", true);
147: RegisterActiveX(Path.Combine(flash32Path, string.Format("Flash32_{0}.ocx", SystemInfo.GetVersionPath())));
148:
149: if (Environment.Is64BitOperatingSystem) {
150: form.UpdateProgressLabel("Activating 64-bit Flash Player for Internet Explorer...", true);
151: RegisterActiveX(Path.Combine(flash64Path, string.Format("Flash64_{0}.ocx", SystemInfo.GetVersionPath())));
152: }
153: }
154: }
155:
156: public static void Install(IProgressForm form, InstallFlags flags) {
157: if (flags.IsNoneSet()) {
158: // No packages should be installed.
159: return;
160: }
161:
162: using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("CleanFlashInstaller.cleanflash.7z")) {
163: using (SevenZipArchive archive = SevenZipArchive.Open(stream)) {
164: InstallFromArchive(archive, form, flags);
165: }
166: }
167: }
168: }
169: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.