private void wc_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { downloadProgress = e.ProgressPercentage; InstallProgress?.Invoke(this, e); }
async private void continueUpdate(Process proc) { string path = proc.MainModule.FileName; operation = "UPDATE"; BetaRadio.Hide(); InstallButton.Hide(); UninstallButton.Hide(); UpdateButton.Hide(); ReinjectButton.Hide(); StatusText.Show(); InstallProgress.Show(); InstallProgress.Value = 0; string tempPath = Path.Combine(Path.GetTempPath(), "EnhancedDiscord"); if (Directory.Exists(tempPath)) { try { Directory.Delete(tempPath, true); } catch (Exception e) { StatusText.Text = "Error deleting temp folders."; Logger.Log(StatusText.Text + " " + e.Message); } } Directory.CreateDirectory(tempPath); StatusText.Text = "Downloading package..."; Logger.Log(StatusText.Text); string zipPath = Path.Combine(tempPath, "EnhancedDiscord.zip"); string zipLink = Properties.Resources.zipLink + branch; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; WebClient wc = new WebClient(); try { await wc.DownloadFileTaskAsync(new Uri(zipLink), zipPath); } catch (Exception e) { Logger.Error("Failed to download ED files. " + e.Message); endInstallation("Failed to download ED files.", true); return; } InstallProgress.Value = 40; StatusText.Text = "Successfully downloaded. Extracting..."; Logger.Log(StatusText.Text); try { ZipFile.ExtractToDirectory(zipPath, tempPath); } catch (Exception e) { Logger.Error("Failed to extract zip file. " + e.Message); endInstallation("Failed to extract zip file.", true); return; } InstallProgress.Value = 50; StatusText.Text = "Finished extracting zip. Checking core..."; Logger.Log(StatusText.Text); string extractedPath = Path.Combine(tempPath, "EnhancedDiscord-" + branch); string enhancedPath = "./EnhancedDiscord"; if (!File.Exists(Path.Combine(enhancedPath, "config.json"))) { try { File.WriteAllText(Path.Combine(enhancedPath, "config.json"), "{}"); } catch (Exception e) { Logger.Error("Failed to write config.json. " + e.Message); } } string[] garbage = new string[] { "README.md", "plugins.md", ".gitignore", "advanced_installation.md" }; foreach (string file in Directory.GetFiles(extractedPath)) { string filename = Path.GetFileName(file); if (Array.Exists(garbage, f => f == filename)) { continue; } string equiv = Path.Combine(enhancedPath, filename); bool filesEqual = false; bool fileExists = File.Exists(equiv); if (fileExists) { filesEqual = FilesEqual(file, equiv); } try { if (fileExists && !filesEqual) { File.Delete(equiv); } if (!fileExists || !filesEqual) { File.Copy(file, equiv); } } catch (Exception e) { StatusText.Text = "Could not update plugin: " + filename; Logger.Log(StatusText.Text + " " + e.Message); } } InstallProgress.Value = 70; StatusText.Text = "Core finished. Checking plugins..."; Logger.Log(StatusText.Text); string pluginPath = Path.Combine(enhancedPath, "plugins"); if (!Directory.Exists(pluginPath)) { Directory.CreateDirectory(pluginPath); } foreach (string file in Directory.GetFiles(Path.Combine(extractedPath, "plugins"))) { string filename = Path.GetFileName(file); if (filename == "style.css") { continue; } string equiv = Path.Combine(pluginPath, filename); bool filesEqual = false; bool fileExists = File.Exists(equiv); if (fileExists) { filesEqual = FilesEqual(file, equiv); } try { if (fileExists && !filesEqual) { File.Delete(equiv); } if (!fileExists || !filesEqual) { File.Copy(file, equiv); } } catch (Exception e) { StatusText.Text = "Could not update plugin: " + filename; Logger.Log(StatusText.Text + " " + e.Message); } } StatusText.Text = "Cleaning up..."; Logger.Log(StatusText.Text); if (Directory.Exists(tempPath)) { try { Directory.Delete(tempPath, true); } catch (Exception e) { StatusText.Text = "Error deleting temp folders."; Logger.Log(StatusText.Text + " " + e.Message); } } InstallProgress.Value = 90; endInstallation("ED files updated.", false); return; }
private void InstallButton_Click(object sender, EventArgs e) { if (BetaRadio.Checked) { branch = "beta"; } BetaRadio.Hide(); InstallButton.Hide(); UninstallButton.Hide(); UpdateButton.Hide(); ReinjectButton.Hide(); StatusText.Show(); InstallProgress.Show(); StatusText.Text = "Finding Discord processes..."; Process[] stable = Process.GetProcessesByName("Discord"); Process[] canary = Process.GetProcessesByName("DiscordCanary"); Process[] ptb = Process.GetProcessesByName("DiscordPtb"); Process[] dev = Process.GetProcessesByName("DiscordDevelopment"); List <Process> discordProcesses = new List <Process>(); discordProcesses.AddRange(stable); discordProcesses.AddRange(canary); discordProcesses.AddRange(ptb); discordProcesses.AddRange(dev); if (discordProcesses.Count == 0) { endInstallation("No Discord processes found. Please open Discord and try again.", true); return; } List <Process> uniqueProcesses = new List <Process>(); // First look for processes with unique filenames that have a title for (int i = 0; i < discordProcesses.Count; i++) { bool isUnique = true; for (int j = 0; j < uniqueProcesses.Count; j++) { if (uniqueProcesses[j].MainModule.FileName.Equals(discordProcesses[i].MainModule.FileName)) { isUnique = false; break; } } if (!isUnique || discordProcesses[i].MainWindowTitle == "" || discordProcesses[i].MainWindowTitle.StartsWith("Developer Tools")) { continue; } uniqueProcesses.Add(discordProcesses[i]); } // Then look for all processes with unique filenames for (int i = 0; i < discordProcesses.Count; i++) { bool isUnique = true; for (int j = 0; j < uniqueProcesses.Count; j++) { if (uniqueProcesses[j].MainModule.FileName.Equals(discordProcesses[i].MainModule.FileName)) { isUnique = false; break; } } if (!isUnique) { continue; } uniqueProcesses.Add(discordProcesses[i]); } StatusText.Text = "Found " + uniqueProcesses.Count + " Discord process" + (uniqueProcesses.Count == 1 ? "" : "es") + "."; InstallProgress.Value = 10; Process finalProcess = uniqueProcesses[0]; if (uniqueProcesses.Count > 1) { // Enable selection buttons List <Button> clients = new List <Button>(); for (int i = 0; i < uniqueProcesses.Count; i++) { if (canary.Contains(uniqueProcesses[i])) { CanaryButton.Show(); clients.Add(CanaryButton); canaryProcess = uniqueProcesses[i]; } else if (ptb.Contains(uniqueProcesses[i])) { PTBButton.Show(); clients.Add(PTBButton); ptbProcess = uniqueProcesses[i]; } else if (dev.Contains(uniqueProcesses[i])) { DevButton.Show(); clients.Add(DevButton); devProcess = uniqueProcesses[i]; } else if (stable.Contains(uniqueProcesses[i])) { StableButton.Show(); clients.Add(StableButton); stableProcess = uniqueProcesses[i]; } } // position buttons correctly if (clients.Count == 3) { clients[0].Left = 55; clients[1].Left = 131; clients[2].Left = 207; } else if (clients.Count == 2) { clients[0].Left = 88; clients[1].Left = 164; } return; // stuff continues w/ button events } if (operation == "UPDATE") { continueUpdate(finalProcess); } else { continueInstall(finalProcess); } }
public static ActionResult ExecuteSQLScripts(Session session) { try { MessageResult iResult; string sInstallLocation, sServidor, sBaseDatos, sMensaje; int iTotalTicks, iTickIncrement = 1; bool isCustomActionData = true; if (session == null) { throw new ArgumentNullException("session"); } sInstallLocation = GetSessionProperty(session, "INSTALLLOCATION", isCustomActionData); sServidor = GetSessionProperty(session, "DATABASE_SERVERNAME", isCustomActionData); sBaseDatos = GetSessionProperty(session, "DATABASE_NAME", isCustomActionData); List <DataBasePathTO> listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); List <FeactureInstallTO> listF = session.CustomActionData.GetObject <List <FeactureInstallTO> >("DATABASE_FEACTURESCRIPTS"); iTotalTicks = listF.Count; InstallUtilities.WriteLogInstall(session, "Starting ExecuteSQLScripts ...", null, true); iResult = InstallProgress.ResetProgress(session, iTotalTicks); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } sMensaje = "SQL Server: " + sServidor; iResult = InstallProgress.DisplayStatusActionStart(session, sMensaje, sMensaje, "[1] / [2]: [3]"); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } iResult = InstallProgress.NumberOfTicksPerActionData(session, iTickIncrement, true); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } for (int i = 0; i < listF.Count; i++) { ExecuteSQLScript(session, listF[i].DirectoryPath, listF[i].FileName, isCustomActionData); iResult = InstallProgress.DisplayActionData3(session, (i + 1).ToString(), iTotalTicks.ToString(), InstallUtilities.Right(Path.Combine(listF[i].DirectoryPath, listF[i].FileName), 200)); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } } return(ActionResult.Success); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception raised when execute database script", ex, true); MessageBox.Show(ex.Message, "Error of scripts execution (ExecuteSQLScripts(Session session))", MessageBoxButtons.OK, MessageBoxIcon.Error); return(ActionResult.Failure); } }
public static ActionResult ExecuteSQLScripts(Session session) { try { // Active message only for debugging developing // MessageBox.Show ( " ExecuteSQLScripts : To debug in VS Net, on the Debug menu, ' Attach to process ' // Msiexec.exe and rundll32.exe " DEBUG : ExecuteSQLScripts " , MessageBoxButtons.OK , MessageBoxIcon.Information ); MessageResult iResult; string sInstallLocation, sServer, sDatabase, sMessage; int iTotalTicks, iTickIncrement = 1; bool isCustomActionData = true; if (session == null) { throw new ArgumentNullException("session"); } sInstallLocation = GetSessionProperty(session, "INSTALLLOCATION", isCustomActionData); sServer = GetSessionProperty(session, "DATABASE_SERVERNAME", isCustomActionData); sDatabase = GetSessionProperty(session, "DATABASE_NAME", isCustomActionData); List <DataBasePathTO> listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); var listF = session.CustomActionData.GetObject <List <FeatureInstallTO> >("DATABASE_FEACTURESCRIPTS"); iTotalTicks = listF.Count; InstallUtilities.WriteLogInstall(session, "Initialised ExecuteSQLScripts ...", null, true); iResult = InstallProgress.ResetProgress(session, iTotalTicks); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } sMessage = "Executed Script on SQL Server: " + sServer; iResult = InstallProgress.DisplayStatusActionStart(session, sMessage, sMessage, "[1] / [2]: [3]"); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } iResult = InstallProgress.NumberOfTicksPerActionData(session, iTickIncrement, true); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } for (int i = 0; i < listF.Count; i++) { ExecuteSQLScript(session, listF[i].DirectoryPath, listF[i].FileName, isCustomActionData); iResult = InstallProgress.DisplayActionData3(session, (i + 1).ToString(), iTotalTicks.ToString(), InstallUtilities.Right(Path.Combine(listF[i].DirectoryPath, listF[i].FileName), 200)); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } } return(ActionResult.Success); } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, @"Exception executing script against the database", ex, true); MessageBox.Show(ex.Message, @"Error while executing scripts", MessageBoxButtons.OK, MessageBoxIcon.Error); return(ActionResult.Failure); } }
public static ActionResult ExecuteSQLScripts(Session session) { var data = new CustomActionData(); try { // Active message only for debugging developing // MessageBox.Show("SwhowPathInstall: For debugging , the Debug menu, ' Attach to process ' ate processes : msiexec.exe y rundll32.exe.", // "Depurar: SwhowPathInstall", MessageBoxButtons.OK, MessageBoxIcon.Information); //bool isCustomActionData = false; //List<DataBasePathTO> listPaths; List <FeatureInstallTO> listFeactureScripts; var listFeactureNames = new List <string>(); InstallUtilities.WriteLogInstall(session, "Initialised SwhowPathInstall ...", null, true); if (session == null) { throw new ArgumentNullException("session"); } // Setup Routes taken from CustomTable Id = " TABLE_DATABASE_PATHS " and set default route //listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); // Open the user form to change installation paths database . /* * var frmA = new frmPaths(listPaths); * if (frmA.ShowDialog() != DialogResult.OK) * { * MessageBox.Show("Error"); * throw new InstallerException("Configuración de rutas de instalación no realizada"); * } */ // / Prepare CustomActionData for deferred CustomAction // Update CustomTable Id = " TABLE_DATABASE_PATHS " with modified routes // UpdateCustomTableDataBasePaths (session , listPaths , isCustomActionData ); // Prepare list of paths to be sent to CustomActionData for deferred CustomAction //data.AddObject("DATABASE_PATHS", listPaths); // Add the route list as a session property // Data.Add ( " DATABASE_PATHS " JsonConvert.SerializeObject ( listPaths ) ) ; // To retrieve the serialized property // List <DataBasePathTO> JsonConvert.DeserializeObject listPaths = < List <DataBasePathTO> > ( session.CustomActionData [" DATABASE_PATHS "] ); // Prepare properties to be sent to CustomActionData for deferred CustomAction SetCustomActionData(session, "INSTALLLOCATION", data); SetCustomActionData(session, "DATABASE_SERVERNAME", data); SetCustomActionData(session, "DATABASE_NAME", data); SetCustomActionData(session, "DATABASE_WINDOWSAUTHENTICATION", data); SetCustomActionData(session, "DATABASE_AUTHENTICATEDATABASE", data); SetCustomActionData(session, "DATABASE_EXECUTESCRIPTS", data); SetCustomActionData(session, "DATABASE_USERNAME", data); SetCustomActionData(session, "DATABASE_PASSWORD", data); SetCustomActionData(session, "DATABASE_PROXYPASSWORD", data); SetCustomActionData(session, "DATABASE_MAILPROFILENAME", data); SetCustomActionData(session, "DATABASE_MAILBOX", data); SetCustomActionData(session, "DATABASE_MAILIP", data); SetCustomActionData(session, "DATABASE_OPERATORNAMENAME", data); SetCustomActionData(session, "DATABASE_OPERATORMAILBOX", data); SetCustomActionData(session, "DATABASE_PROXYWINDOWSUSER", data); // / Database Scripts to be installed, taken from the MSI Feature using sql files * . foreach (FeatureInfo fi in session.Features) { if (fi.RequestState == InstallState.Local || fi.RequestState == InstallState.Source || fi.RequestState == InstallState.Default) { listFeactureNames.Add(fi.Name); InstallUtilities.WriteLogInstall(session, "FEATURE fi.Name: " + fi.Name + ", fi.CurrentState: " + fi.CurrentState + ", fi.RequestState:" + fi.RequestState, null, false); } } listFeactureScripts = GetFeatureScriptDataBase(session, listFeactureNames); data.AddObject("DATABASE_FEACTURESCRIPTS", listFeactureScripts); // Add all the properties in a single variable //session["CUSTOMACTIONDATA_PROPERTIES"] = data.ToString(); // Schedule deferred actions //session.DoAction("CA_DataBaseExecuteScripts", data); //return ActionResult.Success; } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, "Exception to establish installation paths for database.", ex, true); return(ActionResult.Failure); } try { // Active message only for debugging developing // MessageBox.Show ( " ExecuteSQLScripts : To debug in VS Net, on the Debug menu, ' Attach to process ' // Msiexec.exe and rundll32.exe " DEBUG : ExecuteSQLScripts " , MessageBoxButtons.OK , MessageBoxIcon.Information ); MessageResult iResult; string sInstallLocation, sServer, sDatabase, sMessage; int iTotalTicks, iTickIncrement = 1; bool isCustomActionData = true; if (session == null) { throw new ArgumentNullException("session"); } // sInstallLocation = GetSessionProperty(session, "INSTALLLOCATION", isCustomActionData); sServer = GetSessionProperty(session, "DATABASE_SERVERNAME", false); //PRESET TO STANDARD DATABASE NAME //sDatabase = GetSessionProperty(session, "DATABASE_NAME", isCustomActionData); //List<DataBasePathTO> listPaths = GetCustomTableDataBasePaths(session, isCustomActionData); var listF = data.GetObject <List <FeatureInstallTO> >("DATABASE_FEACTURESCRIPTS"); iTotalTicks = listF.Count; InstallUtilities.WriteLogInstall(session, "Initialised ExecuteSQLScripts ...", null, true); iResult = InstallProgress.ResetProgress(session, iTotalTicks); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } sMessage = "Executed Script on SQL Server: " + sServer; iResult = InstallProgress.DisplayStatusActionStart(session, sMessage, sMessage, "[1] / [2]: [3]"); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } iResult = InstallProgress.NumberOfTicksPerActionData(session, iTickIncrement, true); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } for (int i = 0; i < listF.Count; i++) { ExecuteSQLScript(session, listF[i].DirectoryPath, listF[i].FileName, isCustomActionData); iResult = InstallProgress.DisplayActionData3(session, (i + 1).ToString(), iTotalTicks.ToString(), InstallUtilities.Right(Path.Combine(listF[i].DirectoryPath, listF[i].FileName), 200)); if (iResult == MessageResult.Cancel) { return(ActionResult.UserExit); } } } catch (Exception ex) { InstallUtilities.WriteLogInstall(session, @"Exception executing script against the database", ex, true); MessageBox.Show(ex.Message, @"Error while executing scripts", MessageBoxButtons.OK, MessageBoxIcon.Error); return(ActionResult.Failure); } return(ActionResult.Success); }