public static void UninstallExistingMsi(string exeOrMsiFullPath, FileDownloadInfo fdi, Form parentForm, bool silentMode, bool autoLogin, string password, bool useWindowsAuth) { var splash = new frmSplash(); try { var p = new Process(); if (fdi.ProductGuid == Guid.Empty && String.IsNullOrEmpty(fdi.UninstallString)) { // this FileDownloadInfo represents the 'new' installer file, and it was not looked up from the registry. var apps = Utility.ListInstalledApplications(); apps.TryGetValue(fdi.DisplayName, out fdi); // now, fdi represents the currently installed version info, meaning the uninstall info, if any, should be present. } if (fdi.ProductGuid != Guid.Empty) { splash.ChangeText(getDisplayMember("UninstallExistingMsi{start}", "Uninstalling version {0} of {1}, please be patient...", fdi.InstalledVersion, fdi.DisplayName)); //string logFileName = exeOrMsiFullPath + ".uninstall_log"; // "B" format in following line means: // 32 digits separated by hyphens, enclosed in brackets: // {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} //p.StartInfo = new ProcessStartInfo("msiexec.exe", " " + (silentMode ? " /passive " : "") + (autoLogin ? @" AUTOLOGIN=""TRUE"" " : "") + @" USEWINDOWSAUTH=""" + useWindowsAuth.ToString().ToUpper() + @""" PASSWORD=""" + password + @""" /L*v """ + logFileName + @""" /X" + fdi.ProductGuid.ToString("B")); var encPassword = Utility.EncryptText(password); p.StartInfo = new ProcessStartInfo("msiexec.exe", " " + (silentMode ? " /passive " : "") + (autoLogin ? @" AUTOLOGIN=""TRUE"" " : "") + @" USEWINDOWSAUTH=""" + useWindowsAuth.ToString().ToUpper() + @""" PASSWORD=""" + encPassword + @""" /X" + fdi.ProductGuid.ToString("B")); p.Start(); p.WaitForExit(); waitForMsiToFinish(parentForm, "/X" + fdi.ProductGuid.ToString("B")); // waitForMsiToFinish(parentForm, fdi.FileName ?? fdi.ProductGuid.ToString("B")); } else if (!String.IsNullOrEmpty(fdi.UninstallString)) { splash.ChangeText(getDisplayMember("UninstallExistingMsi{start}", "Uninstalling version {0} of {1}, please be patient...", fdi.InstalledVersion, fdi.DisplayName)); p.StartInfo = new ProcessStartInfo("cmd.exe", " /k " + fdi.UninstallString); p.Start(); p.WaitForExit(); } } finally { splash.Close(); } }
private void createDatabaseUser(frmSplash splash, DatabaseEngineUtil dbEngineUtil, string superUserPassword, string userName, string userPassword) { try { splash.ChangeText(getDisplayMember("createDatabaseUser{start}", "Creating database users as needed...")); var dnsName = Dns.GetHostName(); var netBIOSName = Toolkit.Cut(dnsName, 0, 15); var output = ""; if (dbEngineUtil is SqlServerEngineUtil) { // SQL Server and using Windows Authentication... // XP output = dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "NETWORK SERVICE", netBIOSName, null, false, true); EventLog.WriteEntry("GRIN-Global Web Application", "Created db user NETWORK SERVICE allowed from machine " + netBIOSName + "... Result: " + output, EventLogEntryType.Information); output = dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "ASPNET", netBIOSName, null, false, true); EventLog.WriteEntry("GRIN-Global Web Application", "Created db user ASPNET allowed from machine " + netBIOSName + "... Result: " + output, EventLogEntryType.Information); // Vista output = dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "NETWORK SERVICE", "NT AUTHORITY", null, false, true); EventLog.WriteEntry("GRIN-Global Web Application", "Created db user NETWORK SERVICE allowed from machine NT AUTHORITY" + "... Result: " + output, EventLogEntryType.Information); output = dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "SYSTEM", "NT AUTHORITY", null, false, true); EventLog.WriteEntry("GRIN-Global Web Application", "Created db user SYSTEM allowed from machine NT AUTHORITY" + "... Result: " + output, EventLogEntryType.Information); // Windows 7 output = dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "DEFAULTAPPPOOL", "IIS AppPool", null, false, true); EventLog.WriteEntry("GRIN-Global Web Application", "Created db user DEFAULTAPPPOOL allowed from machine " + netBIOSName + "... Result: " + output, EventLogEntryType.Information); // SQL Server mixed mode... output = dbEngineUtil.CreateUser(superUserPassword, "gringlobal", userName, netBIOSName, userPassword, false, false); EventLog.WriteEntry("GRIN-Global Web Application", "Created db user " + userName + " allowed from machine " + netBIOSName + "... Result: " + output, EventLogEntryType.Information); } else if (dbEngineUtil is MySqlEngineUtil) { output = dbEngineUtil.CreateUser(superUserPassword, "gringlobal", userName, "%", userPassword, false, false); EventLog.WriteEntry("GRIN-Global Web Application", "Created db user " + userName + " allowed from machine % ... Result: " + output, EventLogEntryType.Information); } else if (dbEngineUtil is OracleEngineUtil) { output = dbEngineUtil.CreateUser(superUserPassword, "gringlobal", userName, null, userPassword, false, false); EventLog.WriteEntry("GRIN-Global Web Application", "Created db user " + userName + " allowed from machine [null] ... Result: " + output, EventLogEntryType.Information); } else if (dbEngineUtil is PostgreSqlEngineUtil) { output = dbEngineUtil.CreateUser(superUserPassword, "gringlobal", userName, dnsName, userPassword, false, false); EventLog.WriteEntry("GRIN-Global Web Application", "Created db user " + userName + " allowed from machine " + dnsName + "... Result: " + output, EventLogEntryType.Information); } } catch (Exception exCreateUsers) { //Context.LogMessage("Exception creating users: " + exCreateUsers.Message); EventLog.WriteEntry("GRIN-Global Web Application", "Exception creating user(s): " + exCreateUsers.Message, EventLogEntryType.Error); //MessageBox.Show("could not create db user: " + exCreateUsers.Message); } }
private void cmiExport_Click(object sender, EventArgs e) { if (lvDataviews.SelectedItems.Count > 0) { sfdExport.FileName = DateTime.Now.ToString("yyyy_MM_dd_"); if (lvDataviews.SelectedItems.Count == 1) { sfdExport.FileName += lvDataviews.SelectedItems[0].Text; } else { sfdExport.FileName += lvDataviews.SelectedItems.Count; } sfdExport.OverwritePrompt = true; sfdExport.SupportMultiDottedExtensions = true; if (DialogResult.OK == sfdExport.ShowDialog(this)) { var dvs = new List <string>(); var splash = new frmSplash(); foreach (ListViewItem lvi in lvDataviews.SelectedItems) { dvs.Add(lvi.Tag.ToString()); } splash.Show("Exporting " + dvs.Count + " dataview(s)...", false, this); processInBackground( (worker) => { var ds = AdminProxy.ExportDataViewDefinitions(dvs); BinaryFormatter bin = new BinaryFormatter(); using (StreamWriter sw = new StreamWriter(sfdExport.FileName)) { ds.RemotingFormat = SerializationFormat.Binary; bin.Serialize(sw.BaseStream, ds); } }, (worker2, e2) => { splash.ChangeText(getDisplayMember("export{working}", "Still working...")); }, (worker3, e3) => { splash.Close(); MainFormUpdateStatus(getDisplayMember("export{exported}", "Exported {0} dataview(s)", dvs.Count.ToString("###,##0")), true); }); } } }
private void createDatabaseUser(frmSplash splash, DatabaseEngineUtil dbEngineUtil, string superUserPassword, string userName, string userPassword) { try { splash.ChangeText(getDisplayMember("createDatabaseUser{start}", "Creating database users as needed...")); var dnsName = Dns.GetHostName(); if (dbEngineUtil is SqlServerEngineUtil) { var netBIOSName = Toolkit.Cut(dnsName, 0, 15); // SQL Server, Integrated authority -- XP dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "NETWORK SERVICE", netBIOSName, null, false, true); dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "ASPNET", netBIOSName, null, false, true); // SQL Server, Integrated authority -- Vista dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "NETWORK SERVICE", "NT AUTHORITY", null, false, true); dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "SYSTEM", "NT AUTHORITY", null, false, true); // SQL Server, Integrated authority -- Windows 7 dbEngineUtil.CreateUser(superUserPassword, "gringlobal", "DEFAULTAPPPOOL", "IIS AppPool", null, false, true); // SQL Server mixed mode dbEngineUtil.CreateUser(superUserPassword, "gringlobal", userName, netBIOSName, userPassword, false, false); } else if (dbEngineUtil is MySqlEngineUtil) { dbEngineUtil.CreateUser(superUserPassword, "gringlobal", userName, "*", userPassword, false, false); } else if (dbEngineUtil is OracleEngineUtil) { dbEngineUtil.CreateUser(superUserPassword, "gringlobal", userName, null, userPassword, false, false); } else if (dbEngineUtil is PostgreSqlEngineUtil) { dbEngineUtil.CreateUser(superUserPassword, "gringlobal", userName, dnsName, userPassword, false, false); } } catch (Exception exCreateUsers) { //Context.LogMessage("Exception creating users: " + exCreateUsers.Message); //MessageBox.Show("could not create db user: "******"GRIN-Global Search Engine", "Exception creating users: " + exCreateUsers.Message); } }
public override void Install(IDictionary stateSaver) { base.Install(stateSaver); var splash = new frmSplash(); try { string targetDir = Utility.GetTargetDirectory(Context, stateSaver, "Web Application"); string gguacPath = Toolkit.ResolveFilePath(targetDir + @"\gguac.exe", false); //MessageBox.Show("config file=" + configFile); splash.ChangeText(getDisplayMember("Install{extracting}", "Extracting bundled files...")); var utility64CabPath = Toolkit.ResolveFilePath(targetDir + @"\utility64.cab", false); var utility64ExePath = Toolkit.ResolveFilePath(targetDir + @"\ggutil64.exe", false); var tempPath = Utility.GetTempDirectory(100); if (!File.Exists(utility64ExePath)) { if (File.Exists(utility64CabPath)) { // wipe out any existing utility64.exe file in the temp folder var extracted = Toolkit.ResolveFilePath(tempPath + @"\ggutil64.exe", false); if (File.Exists(extracted)) { File.Delete(extracted); } // extract it from our cab var cabOutput = Utility.ExtractCabFile(utility64CabPath, tempPath, gguacPath); // move it to the final target path (we can't do this up front because expand.exe tells us "can't expand cab file over itself" for some reason. if (File.Exists(extracted)) { File.Move(extracted, utility64ExePath); } } } // update the config file... string configFile = Toolkit.ResolveFilePath(targetDir + @"\web.config", false); if (File.Exists(configFile)) { splash.ChangeText(getDisplayMember("Install{verifying}", "Verifying database connection...")); string superUserPassword = Utility.GetSuperUserPassword(Context, stateSaver); bool? useWindowsAuth = Utility.GetUseWindowsAuthentication(Context, stateSaver); DatabaseEngineUtil dbEngineUtil = promptForDatabaseConnectionInfo(splash, ref superUserPassword, ref useWindowsAuth); createDatabaseUser(splash, dbEngineUtil, superUserPassword, "gg_user", "PA55w0rd!"); string connectionString = null; if (useWindowsAuth == true) { connectionString = dbEngineUtil.GetDataConnectionSpec("gringlobal", null, null).ConnectionString; } else { connectionString = dbEngineUtil.GetDataConnectionSpec("gringlobal", "gg_user", "PA55w0rd!").ConnectionString; } EventLog.WriteEntry("GRIN-Global Web Application", "Database connection string=" + connectionString, EventLogEntryType.Information); splash.ChangeText(getDisplayMember("Install{writingconfig}", "Writing configuration file...")); string contents = File.ReadAllText(configFile); string appSetting = @"<add providerName=""__ENGINE__"" name=""DataManager"" connectionString=""__CONNECTION_STRING__"" />".Replace("__ENGINE__", dbEngineUtil.EngineName).Replace("__CONNECTION_STRING__", connectionString); contents = contents.Replace("<!-- __CONNECTIONSTRING__ -->", appSetting); contents = contents.Replace("<!-- __COMMENT__ -->", "<!-- TESTING "); contents = contents.Replace("<!-- __ENDCOMMENT__ -->", " -->"); File.WriteAllText(configFile, contents); } // give ASPNET user full control to the ~/uploads folder splash.ChangeText(getDisplayMember("Install{settingperms}", "Setting permissions on uploads folder...")); assignFolderPermissions(Utility.ResolveDirectoryPath(targetDir + @"\uploads", true)); } catch (Exception ex) { MessageBox.Show(getDisplayMember("Install{failed}", "Error: {0}", ex.Message)); throw; } finally { splash.Close(); } }
private void frmProgress_Activated(object sender, EventArgs e) { if (_activatedBefore) { return; } _activatedBefore = true; this.DialogResult = DialogResult.Cancel; Application.DoEvents(); _cancel = false; var files = _files; string downloadCache = FileDownloadInfo.DownloadedCacheFolder(_componentType); string installCache = FileDownloadInfo.InstalledCacheFolder(_componentType); // determine how many files we have, how many bytes we have to downloaded int totalCount = 0; long totalBytes = 0; string url = null; foreach (var key in files.Keys) { totalCount += files[key].Count; foreach (var di in files[key]) { totalBytes += di.SizeInBytes; if (url == null) { url = di.AbsoluteUrl.Replace(di.AppRelativeUrl.Replace("~", ""), ""); } } } int currentCount = 1; long totalBytesRead = 0; lblStatus.Text = "Initializing..."; lblOverallDownload.Text = "Initializing..."; lblOverallInstall.Text = "Initializing..."; lblURL.Text = url; pbOverallDownload.Maximum = (int)totalBytes / 1024; Application.DoEvents(); // for each row in the datagrid foreach (var key in files.Keys) { var filesToDownload = files[key]; string filePath = (downloadCache + @"\" + key).Replace("~", "").Replace("//", @"\").Replace(@"\\", @"\") + @"\"; // If the .msi is marked as needing downloading, the associated setup.exe will // also be marked as needing downloading. // If there is no setup.exe with the .msi, we still want to download the msi. // for each file associated with each row in the datagrid foreach (var downloadInfo in filesToDownload) { downloadInfo.FullFilePath = filePath + downloadInfo.FileName; Utility.ResolveFilePath(downloadInfo.FullFilePath, true); lblStatus.Text = "Downloading " + downloadInfo.FileName + " (" + currentCount + " of " + totalCount + ")..."; if (downloadInfo.NeedToDownload) { if (Utility.IsWindowsFilePath(downloadInfo.AbsoluteUrl)) { // simply copy file from source path to destination path if (File.Exists(downloadInfo.FullFilePath)) { File.Delete(downloadInfo.FullFilePath); } File.Copy(downloadInfo.AbsoluteUrl, downloadInfo.FullFilePath); // and the flag file so if they connect to a web server later we know which version the cached one is File.WriteAllText(downloadInfo.FullFilePath + ".version", downloadInfo.LatestVersion); totalBytesRead += downloadInfo.SizeInBytes; } else { downloadFileFromWebServer(downloadInfo, ref totalBytesRead, ref totalBytes); } } else { totalBytesRead += downloadInfo.SizeInBytes; } // add to the progress bar the bytes for this file (in case download was skipped) decimal percentTotalDone = ((decimal)totalBytesRead / (decimal)totalBytes) * 100.0M; //50.0M; lblOverallDownload.Text = percentTotalDone.ToString("##0.00") + "% of all files downloaded"; int overallVal = (int)(totalBytesRead / 1024); pbOverallDownload.Value = (overallVal > pbOverallDownload.Maximum ? pbOverallDownload.Maximum : overallVal); currentCount++; Application.DoEvents(); if (_cancel) { break; } } } bool installFailed = false; string failedInstallName = ""; if (!_cancel) { lblCurrentAction.Text = "100% downloaded"; pbFile.Value = pbFile.Maximum; lblOverallDownload.Text = "100% of all files downloaded"; pbOverallDownload.Value = pbOverallDownload.Maximum; this.WindowState = FormWindowState.Minimized; Application.DoEvents(); if (_performInstallation) { btnCancel.Enabled = false; Text = "Installing..."; if (this.Owner != null) { this.Owner.WindowState = FormWindowState.Minimized; } Utility.ActivateApplication(this.Handle); Application.DoEvents(); int totalInstallCount = 0; int installCount = 0; foreach (var key in files.Keys) { foreach (var di in files[key]) { if (di.NeedToInstall) { totalInstallCount++; } } } pbOverallInstall.Maximum = totalInstallCount; // for each row in the datagrid foreach (var key in files.Keys) { var filesToDownload = files[key]; string filePath = (downloadCache + @"\" + key).Replace("~", "").Replace("//", @"\").Replace(@"\\", @"\") + @"\"; // If the .msi is marked as needing downloading, the associated setup.exe will // also be marked as needing downloading. // If there is no setup.exe with the .msi, we still want to download the msi. var installed = new List <string>(); var installedInfo = new List <FileDownloadInfo>(); // for each file associated with the current row in the datagrid foreach (var downloadInfo in filesToDownload) { if (downloadInfo.NeedToInstall) { lblStatus.Text = "Installing " + downloadInfo.FileName; lblCurrentAction.Text = "Installing " + downloadInfo.FileName; this.Text = lblCurrentAction.Text; lblOverallInstall.Text = "Installing..."; string logFileName = null; Application.DoEvents(); if (downloadInfo.FileName.ToLower().EndsWith(".exe")) { // install it!!! if (_installingNewUpdater) { // an exe locks files when it's running -- meaning if we try to update the updater while it's running, // we're guaranteed it will fail. copyForMirrorIfNeeded(filePath, downloadInfo); var batFilePath = createBatchFileToUpdateUpdater(downloadInfo, null); runBatchFile(batFilePath); this.DialogResult = DialogResult.OK; this.Close(); return; } else { string msiName = installViaSetupExe(filePath + downloadInfo.FileName, downloadInfo, out logFileName); } installed.Add(downloadInfo.FileName.ToLower().Replace(".exe", "")); } else if (downloadInfo.FileName.ToLower().EndsWith(".msi")) { string file = downloadInfo.FileName.ToLower().Replace(".msi", ""); if (!installed.Contains(file)) { // this is a free msi -- no .exe is associated with it. if (_installingNewUpdater) { // an exe locks files when it's running -- meaning if we try to update the updater while it's running, // we're guaranteed it will fail. copyForMirrorIfNeeded(filePath, downloadInfo); var batFilePath = createBatchFileToUpdateUpdater(null, downloadInfo); runBatchFile(batFilePath); this.DialogResult = DialogResult.OK; this.Close(); return; } else { // 'normal' msi install installViaMsiExec(filePath + downloadInfo.FileName, downloadInfo, out logFileName); } // installedInfo.Add(downloadInfo); } else { // the exe installed it, just skip this msi } } else if (downloadInfo.FileName.ToLower().EndsWith(".zip")) { // this is a .zip file, just open it in explorer // TODO: auto-unzip? distribute a .cab instead??? Process.Start("explorer.exe", @"/select,""" + downloadInfo.FullFilePath + @""""); } else if (downloadInfo.FileName.ToLower().EndsWith(".cab")) { // auto-extract to a temp folder or prompt them to extract it somewhere? var fCab = new frmExpand(); fCab.txtExpandTo.Text = Utility.GetTempDirectory(1500) + @"\" + downloadInfo.DisplayName; fCab.ShowDialog(this); var splash = new frmSplash(); try { if (fCab.rdoExpand.Checked) { // expand cab file, launch var dest = Utility.ResolveDirectoryPath(fCab.txtExpandTo.Text, true); if (fCab.chkEmptyDirectory.Checked) { splash.ChangeText(getDisplayMember("activated{emptying}", "Emptying directory {0} ...", dest)); Utility.EmptyDirectory(dest); } splash.ChangeText(getDisplayMember("activated{extracting}", "Extracting {0}...", downloadInfo.FileName)); Utility.ExtractCabFile(downloadInfo.FullFilePath, dest, null); if (fCab.chkLaunchSetup.Checked) { var setupBat = Utility.ResolveFilePath(dest + @"\Setup.bat", false); if (File.Exists(setupBat)) { // launch setup.bat... Process.Start(dest + @"\Setup.bat"); } else { Process.Start("explorer.exe", @"""" + dest + @""""); } } else { Process.Start("explorer.exe", @"""" + dest + @""""); } } else { Process.Start("explorer.exe", @"/select,""" + downloadInfo.FullFilePath + @""""); } } finally { splash.Close(); } } else { // we don't know what this is, just display it in explorer Process.Start("explorer.exe", @"/select,""" + filePath + @""""); } if (downloadInfo.NeedToInstall && downloadInfo.TriedToInstall) { if (!File.Exists(logFileName)) { failedInstallName = downloadInfo.DisplayName; installFailed = true; break; } else { string logText = File.ReadAllText(logFileName); if (logText.Contains("-- Installation failed.")) { installFailed = true; failedInstallName = downloadInfo.DisplayName; break; } } } installCount++; pbOverallInstall.Value = installCount / totalInstallCount; lblOverallInstall.Text = (((decimal)installCount / (decimal)totalInstallCount) * 100.0M).ToString("##0.00") + "% installed"; Application.DoEvents(); if (_cancel) { break; } } } if (!installFailed) { foreach (var di in filesToDownload) { if (di.TriedToInstall) { // move from downloadcache to installercache string curFilePath = filePath + di.FileName; string newFilePath = curFilePath.Replace(downloadCache, installCache); if (File.Exists(newFilePath)) { File.Delete(newFilePath); } Utility.ResolveDirectoryPath(Directory.GetParent(newFilePath).FullName, true); File.Move(curFilePath, newFilePath); try { if (File.Exists(curFilePath + ".version")) { File.Delete(curFilePath + ".version"); } } catch { // ignore all errors, it will be overwritten as needed later anyway } if (_cancel) { break; } } } } if (_cancel || installFailed) { break; } } if (this.Owner != null) { this.Owner.WindowState = FormWindowState.Normal; } this.WindowState = FormWindowState.Normal; Application.DoEvents(); Utility.ActivateApplication(this.Handle); if (installFailed) { MessageBox.Show(getDisplayMember("activated", "Install of {0} failed.\n\nAny remaining installs have been cancelled.", failedInstallName)); } } else { // no installing done, just downloading. // if this is a mirror server, be sure to copy to the mirror temp dir if (_isMirrorServer) { foreach (var key in files.Keys) { string filePath = (downloadCache + @"\" + key).Replace("~", "").Replace("//", @"\").Replace(@"\\", @"\") + @"\"; var filesToDownload = files[key]; foreach (var fdi in filesToDownload) { copyForMirrorIfNeeded(filePath, fdi); } } } } } this.DialogResult = (_cancel ? DialogResult.Cancel : DialogResult.OK); }
private void btnImport_Click(object sender, EventArgs e) { var popup = new StringBuilder(); var fname = Path.GetFileName(ofdDataTrigger.FileName); // remove any alternate data streams in case it was downloaded from the internet (otherwise ASPNET won't have access to it) // we do this by using the type orig_file > new_file hack if (File.Exists(ofdDataTrigger.FileName + ".old")) { File.Delete(ofdDataTrigger.FileName + ".old"); } File.Move(ofdDataTrigger.FileName, ofdDataTrigger.FileName + ".old"); if (File.Exists(ofdDataTrigger.FileName + ".bat")) { File.Delete(ofdDataTrigger.FileName + ".bat"); } File.WriteAllText(ofdDataTrigger.FileName + ".bat", String.Format(@" @ECHO OFF type ""{0}"" > ""{1}"" ", ofdDataTrigger.FileName + ".old", ofdDataTrigger.FileName)); var psi = new ProcessStartInfo(); psi.FileName = ofdDataTrigger.FileName + ".bat"; psi.CreateNoWindow = true; psi.WindowStyle = ProcessWindowStyle.Hidden; psi.UseShellExecute = false; var p = Process.Start(psi); p.WaitForExit(); if (!ofdDataTrigger.FileName.ToLower().Contains(getPhysicalFolder().ToLower())) { // file is not in the triggers path the website is expecting it to be. // copy it there now. var newPath = Toolkit.ResolveFilePath(getPhysicalFolder() + @"\" + fname, true); try { using (var splash = new frmSplash()) { // stop IIS (to make sure no processes are holding onto it splash.ChangeText(getDisplayMember("import{stoppingiis}", "Stopping web server...")); var psi2 = new ProcessStartInfo(); psi2.FileName = "iisreset.exe"; psi2.Arguments = "/stop"; psi2.CreateNoWindow = true; psi2.WindowStyle = ProcessWindowStyle.Hidden; psi2.UseShellExecute = false; var p2 = Process.Start(psi2); p2.WaitForExit(); // copy the file in splash.ChangeText(getDisplayMember("import{copyingtriggerfile}", "Copying in data trigger file...")); File.Copy(ofdDataTrigger.FileName, newPath, true); if (File.Exists(ofdDataTrigger.FileName + ".bat")) { File.Delete(ofdDataTrigger.FileName + ".bat"); } splash.ChangeText(getDisplayMember("import{startingiis}", "Starting web server...")); var psi3 = new ProcessStartInfo(); psi3.FileName = "iisreset.exe"; psi3.Arguments = "/start"; psi3.CreateNoWindow = true; psi3.WindowStyle = ProcessWindowStyle.Hidden; psi3.UseShellExecute = false; var p3 = Process.Start(psi3); p3.WaitForExit(); } fname = newPath; } catch (Exception ex) { MessageBox.Show(this, getDisplayMember("import{failed_body}", "Could not load assembly: {0}", ex.Message), getDisplayMember("import{failed_title}", "Invalid Assembly File"), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); DialogResult = DialogResult.Cancel; this.Close(); return; } } // write database entries (safe save - by trigger name, dataview name/ tablename // foreach (ListViewItem lvi in lv.Items) { var ti = lvi.Tag as TagInfo; // add mappings for ones tied to a dataview foreach (var r in ti.Dataviews) { if (r.ID > -1) { AdminProxy.SaveTrigger(-1, r.ID, -1, ti.VirtualPath, ti.AssemblyName, ti.ClassName, ti.Title, ti.Description, true, false); } else { popup.Append("Could not locate dataview '" + r.Name + "' to map data trigger '" + ti.ClassName + "'."); } } // add mappings for ones tied to a table foreach (var r in ti.Tables) { if (r.ID > -1) { AdminProxy.SaveTrigger(-1, -1, r.ID, ti.VirtualPath, ti.AssemblyName, ti.ClassName, ti.Title, ti.Description, true, false); } else { popup.Append("Could not locate table '" + r.Name + "' to map data trigger '" + ti.ClassName + "'."); } } // add mapping for ones tied to neither if (ti.Tables.Count == 0 && ti.Dataviews.Count == 0) { AdminProxy.SaveTrigger(-1, -1, -1, ti.VirtualPath, ti.AssemblyName, ti.ClassName, ti.Title, ti.Description, true, false); } } if (popup.Length > 0) { var f = new frmMessageBox(); f.txtMessage.Text = popup.ToString(); f.btnNo.Text = "OK"; f.btnYes.Visible = false; f.ShowDialog(this); } DialogResult = DialogResult.OK; Close(); }
private void customInstall(IDictionary state) { string targetDir = Utility.GetTargetDirectory(this.Context, state, "Search Engine"); string targetDataDir = Toolkit.ResolveDirectoryPath(@"*COMMONAPPLICATIONDATA*\GRIN-Global\GRIN-Global Search Engine", true); int installerWindowHandle = 0; var splash = new frmSplash(); try { string gguacPath = Toolkit.ResolveFilePath(targetDir + @"\gguac.exe", false); splash.ChangeText(getDisplayMember("customInstall{extracting}", "Extracting bundled files...")); var utility64CabPath = Toolkit.ResolveFilePath(targetDir + @"\utility64.cab", false); var utility64ExePath = Toolkit.ResolveFilePath(targetDir + @"\ggutil64.exe", false); var tempPath = Utility.GetTempDirectory(15); if (!File.Exists(utility64ExePath)) { if (File.Exists(utility64CabPath)) { // wipe out any existing utility64.exe file in the temp folder var extracted = Toolkit.ResolveFilePath(tempPath + @"\ggutil64.exe", false); if (File.Exists(extracted)) { File.Delete(extracted); } // extract it from our cab var cabOutput = Utility.ExtractCabFile(utility64CabPath, tempPath, gguacPath); // move it to the final target path (we can't do this up front because expand.exe tells us "can't expand cab file over itself" for some reason. if (File.Exists(extracted)) { File.Move(extracted, utility64ExePath); } } } // delete any existing index file(s) string indexDir = (targetDataDir + @"\indexes").Replace(@"\\", @"\"); if (Directory.Exists(targetDataDir)) { Directory.Delete(targetDataDir, true); } string helperPath = (Utility.GetTargetDirectory(this.Context, state, "Search Engine") + @"\gguac.exe").Replace(@"\\", @"\"); // prompt user to tell us what to do -- download files or begin recreating locally... var f = new frmInstallIndexes(); f.HelperPath = helperPath; installerWindowHandle = Toolkit.GetWindowHandle("GRIN-Global Search Engine"); //// HACK: try to give MSI form a moment to focus before we show our dialog... //Thread.Sleep(500); //Application.DoEvents(); //Thread.Sleep(500); // we no longer allow user to download indexes. always issue a recreate. File.WriteAllText(Toolkit.ResolveFilePath(indexDir + @"\recreate.init", true), ""); //DialogResult result = DialogResult.Cancel; //var autoIncludeOptionalData = Utility.GetParameter("optionaldata", null, this.Context, null); //if (("" + autoIncludeOptionalData).ToUpper() == "TRUE" || ("" + autoIncludeOptionalData).ToUpper() == "1") { // f.DownloadAllFiles(); // result = DialogResult.OK; //} else if (("" + autoIncludeOptionalData).ToUpper() == "FALSE" || ("" + autoIncludeOptionalData).ToUpper() == "0"){ // result = DialogResult.OK; //} else { // result = f.ShowDialog(installerWindowHandle); //} //if (result == DialogResult.OK) { // if (f.rdoCreateLocally.Checked) { // // need to create locally // File.WriteAllText(Toolkit.ResolveFilePath(indexDir + @"\recreate.init", true), ""); // // EventLog.WriteEntry("GRIN-Global Search Engine", "Should recreate indexes locally...", EventLogEntryType.Information); // } else { // if (f.IndexFiles != null && f.IndexFiles.Count > 0) { // // downloaded files. // splash.Show("Inspecting index files (" + f.IndexFiles.Count + ")...", false, null); // for (var i = 0; i < f.IndexFiles.Count; i++) { // var s = f.IndexFiles[i]; // splash.ChangeText("Extracting index files (" + (i + 1) + " of " + f.IndexFiles.Count + ")..."); // Utility.ExtractCabFile(s, indexDir, helperPath); // // we expanded the cab file, now delete it since we don't need it anymore (and want the next install to re-request data from the server and ignore the cache) // try { // var moveTo = s.Replace(@"\downloaded\", @"\installed\"); // if (File.Exists(moveTo)) { // File.Delete(moveTo); // } // File.Move(s, moveTo); // } catch { // try { // // move failed, try to delete it // File.Delete(s); // } catch { // // ultimately ignore all file movement errors // } // } // } // } else { // EventLog.WriteEntry("GRIN-Global Search Engine", "User chose to download indexes, but selected 0 indexes to download. Empty indexes will be created.", EventLogEntryType.Information); // } // } //} else { // // user cancelled out. // //Context.LogMessage("User cancelled out of choosing to generate indexes locally or download from server"); // EventLog.WriteEntry("GRIN-Global Search Engine", "User cancelled out of choosing to generate indexes locally or download from server"); // // this.Rollback(state); // throw new InvalidOperationException("User cancelled out of choosing to generate indexes locally or download from server."); //} } catch (Exception ex) { splash.Close(); //this.Context.LogMessage("Setup failed to extract the index files: " + ex.Message); EventLog.WriteEntry("GRIN-Global Search Engine", "Setup failed to extract the index files: " + ex.Message); // this.Rollback(state); throw; } // // first unzip the data (note we need to run this is athe currently logged-in user for it to work) // Utility.ExtractCabFile((targetDir + @"\search.cab").Replace(@"\\", @"\"), indexDir, helperPath); //// Utility.Unzip((Utility.DataDirectory + @"\gringlobal_search_small.zip").Replace(@"\\", @"\"), indexDir); string configFile = Toolkit.ResolveFilePath(targetDir + @"\GrinGlobal.Search.Engine.Service.exe.config", false); try { // update the config file... if (File.Exists(configFile)) { splash.ChangeText(getDisplayMember("customInstall{verifying}", "Verifying database connection...")); string superUserPassword = Utility.GetSuperUserPassword(Context, state); bool? useWindowsAuthentication = Utility.GetUseWindowsAuthentication(Context, state); //MessageBox.Show("pw=" + superUserPassword + ", windowsAuth=" + useWindowsAuthentication); DatabaseEngineUtil dbEngineUtil = promptForDatabaseConnectionInfo(splash, ref superUserPassword, ref useWindowsAuthentication); createDatabaseUser(splash, dbEngineUtil, superUserPassword, "gg_search", "gg_search_PA55w0rd!"); string connectionString = null; if (useWindowsAuthentication == true) { connectionString = dbEngineUtil.GetDataConnectionSpec("gringlobal", null, null).ConnectionString; } else { connectionString = dbEngineUtil.GetDataConnectionSpec("gringlobal", "gg_search", "gg_search_PA55w0rd!").ConnectionString; } EventLog.WriteEntry("GRIN-Global Search Engine", "Database connection string=" + connectionString, EventLogEntryType.Information); splash.ChangeText(getDisplayMember("customInstall{writingconfig}", "Writing configuration file...")); string contents = File.ReadAllText(configFile); string appSetting = @"<add providerName=""__ENGINE__"" name=""DataManager"" connectionString=""__CONNECTION_STRING__"" />".Replace("__ENGINE__", dbEngineUtil.EngineName).Replace("__CONNECTION_STRING__", connectionString); contents = contents.Replace("<!-- __CONNECTIONSTRING__ -->", appSetting); contents = contents.Replace("<!-- __COMMENT__ -->", "<!-- TESTING "); contents = contents.Replace("<!-- __ENDCOMMENT__ -->", " -->"); File.WriteAllText(configFile, contents); } } catch (Exception ex) { splash.Close(); //this.Context.LogMessage("Setup failed to update the configuration file (" + configFile + "): " + ex.Message); EventLog.WriteEntry("GRIN-Global Search Engine", "Setup failed to update the configuration file (" + configFile + "): " + ex.Message); // this.Rollback(state); throw; } finally { splash.Close(); if (installerWindowHandle > 0) { Toolkit.RestoreWindow(installerWindowHandle); } } }