private void tsmiOpenReg_Click(object sender, EventArgs e) { if (lvApp.SelectedItems.Count < 1) { return; } foreach (ListViewItem lviTemp in lvApp.SelectedItems) { SoftwareInformation siTemp = ListViewUtil.GetSoftwareInformationOfList(lviTemp, Global.siMain); RegistryKey regkeyTemp = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Applets\Regedit", true); regkeyTemp.SetValue("Lastkey", @"HKLM\" + siTemp.strRegistryLocation, RegistryValueKind.String); regkeyTemp.Close(); Process.Start("regedit.exe"); } }
private void mnuCopy_Click(object sender, EventArgs e) { if (lvApp.SelectedItems.Count < 1) { return; } string EofString = lvApp.SelectedItems.Count > 1 ? "\r\n" : ""; int LoopCount = 0; string strCopyData = ""; foreach (ListViewItem lviTemp in lvApp.SelectedItems) { for (int DisplayIndex = 0; DisplayIndex < lvApp.Columns.Count; DisplayIndex++) { int RealIndex = ListViewUtil.GetIndexByDisplayIndex(lvApp, DisplayIndex); if (RealIndex < 0) { continue; } strCopyData += lviTemp.SubItems[RealIndex].Text + (DisplayIndex == lvApp.Columns.Count - 1 ? (LoopCount++ == lvApp.SelectedItems.Count - 1 ? "" : EofString) : ",\t"); } } try { Clipboard.Clear(); Clipboard.SetText(strCopyData); lblState.Text = "Completed to copy."; } catch { lblState.Text = "Failed to copy."; } }
private void UninstallSelectedItems() { if (lvApp.SelectedItems.Count < 1) { return; } foreach (ListViewItem lviTemp in lvApp.SelectedItems) { try { SoftwareInformation siTemp = ListViewUtil.GetSoftwareInformationOfList(lviTemp, Global.siMain); lblState.Text = "Uninstalling " + siTemp.strDisplayName + ".."; /* * int PID = Interaction.Shell(siTemp.strUninstallString, AppWinStyle.NormalFocus); * if(PID > 0) * { * Process proc = Process.GetProcessById(PID); * if (proc.HasExited) MessageBox.Show("asd"); * proc.EnableRaisingEvents = true; * proc.Exited += new EventHandler(Process_Exited); * // 이벤트 등록하기도 전에 이미 종료됨 * }*/ Process proc = new Process(); proc.StartInfo.FileName = siTemp.strUninstallString; proc.EnableRaisingEvents = true; proc.Exited += new EventHandler(Process_Exited); proc.Start(); //Console.WriteLine("시작 : " + proc.ProcessName); } catch { lblState.Text = "Failed to uninstall."; } } }
private void lvApp_ColumnClick(object sender, ColumnClickEventArgs e) { // lock listview ListViewUtil.LockUpdate(lvApp); // clear column name foreach (ColumnHeader Column in lvApp.Columns) { Column.Text = Column.Text.Replace(" ∨", "").Replace(" ∧", ""); } string strColumnName = lvApp.Columns[e.Column].Text; string strSortType = ""; lblState.Text = "Sorting..."; if (lvApp.Sorting == SortOrder.Ascending || lvApp.Sorting == SortOrder.None) { strSortType = "descending"; lvApp.ListViewItemSorter = new ListViewItemComparer(e.Column, lvApp.Columns[e.Column].Text, SortOrder.Descending); lvApp.Sorting = SortOrder.Descending; lvApp.Columns[e.Column].Text += " ∨"; } else if (lvApp.Sorting == SortOrder.Descending) { strSortType = "ascending"; lvApp.ListViewItemSorter = new ListViewItemComparer(e.Column, lvApp.Columns[e.Column].Text, SortOrder.Ascending); lvApp.Sorting = SortOrder.Ascending; lvApp.Columns[e.Column].Text += " ∧"; } lvApp.Sort(); lblState.Text = "Sorted in " + strSortType + " order by " + strColumnName.ToLower() + "."; // unlock listview ListViewUtil.UnlockUpdate(lvApp); }
private void SetColumnHeaders() { // lock listview ListViewUtil.LockUpdate(lvApp); ColumnHeaderUtil.Add( "Name", iniSettings.Read("Name", "ColumnHeaderWidth", 240), true, iniSettings.Read("Name", "ColumnHeaderDisplayIndex", -1), tsmiViewName ); ColumnHeaderUtil.Add( "Publisher", iniSettings.Read("Publisher", "ColumnHeaderWidth", 200), iniSettings.Read("Publisher", "ColumnHeaderVisible", true), iniSettings.Read("Publisher", "ColumnHeaderDisplayIndex", -1), tsmiViewPublisher ); ColumnHeaderUtil.Add( "Version", iniSettings.Read("Version", "ColumnHeaderWidth", 80), iniSettings.Read("Version", "ColumnHeaderVisible", true), iniSettings.Read("Version", "ColumnHeaderDisplayIndex", -1), tsmiViewVersion ); ColumnHeaderUtil.Add( "Install Time", iniSettings.Read("InstallTime", "ColumnHeaderWidth", 140), iniSettings.Read("InstallTime", "ColumnHeaderVisible", true), iniSettings.Read("InstallTime", "ColumnHeaderDisplayIndex", -1), tsmiViewInstallTime ); ColumnHeaderUtil.Add( "Size", iniSettings.Read("Size", "ColumnHeaderWidth", 80), iniSettings.Read("Size", "ColumnHeaderVisible", true), iniSettings.Read("Size", "ColumnHeaderDisplayIndex", -1), tsmiViewSize ); ColumnHeaderUtil.Add( "Help Link", iniSettings.Read("HelpLink", "ColumnHeaderWidth", 120), iniSettings.Read("HelpLink", "ColumnHeaderVisible", false), iniSettings.Read("HelpLink", "ColumnHeaderDisplayIndex", -1), tsmiViewHelpLink ); ColumnHeaderUtil.Add( "Support Link", iniSettings.Read("SupportLink", "ColumnHeaderWidth", 120), iniSettings.Read("SupportLink", "ColumnHeaderVisible", false), iniSettings.Read("SupportLink", "ColumnHeaderDisplayIndex", -1), tsmiViewSupportLink ); ColumnHeaderUtil.Add( "File Location", iniSettings.Read("FileLocation", "ColumnHeaderWidth", 200), iniSettings.Read("FileLocation", "ColumnHeaderVisible", false), iniSettings.Read("FileLocation", "ColumnHeaderDisplayIndex", -1), tsmiViewFileLocation ); ColumnHeaderUtil.Add( "Registry Location", iniSettings.Read("RegistryLocation", "ColumnHeaderWidth", 200), iniSettings.Read("RegistryLocation", "ColumnHeaderVisible", false), iniSettings.Read("RegistryLocation", "ColumnHeaderDisplayIndex", -1), tsmiViewRegistryLocation ); ColumnHeaderUtil.Create(lvApp); // ======================================================================================= //lvApp.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent); // unlock listview ListViewUtil.UnlockUpdate(lvApp); RefreshInstalledList(); }
private void RefreshAppListView(string strKeyword = "") { lblState.Text = "Scanning..."; // backup sort type at before SortOrder soTemp = lvApp.Sorting; lvApp.Sorting = SortOrder.None; // lock listview ListViewUtil.LockUpdate(lvApp); // clear controls Global.siMain.Clear(); lvApp.Items.Clear(); imglstAppSmall.Images.Clear(); picAppIcon.Image = null; lblDisplayName.Text = ""; lblPublisher.Text = ""; bool isOdd = false; // get registrys foreach (string strUninstallSubkey in Registry.LocalMachine.OpenSubKey(strUninstallRegistryLocation).GetSubKeyNames()) { // write struct SoftwareInformation siTemp = new SoftwareInformation(); // `Registry Location` siTemp.strRegistryLocation = strUninstallRegistryLocation + @"\" + strUninstallSubkey; // get registry sub key RegistryKey regkeyTemp = Registry.LocalMachine.OpenSubKey(siTemp.strRegistryLocation); if (regkeyTemp == null) { continue; } // System Component try { siTemp.isSystemComponent = ((Int32)regkeyTemp.GetValue("SystemComponent") == 1); } catch { siTemp.isSystemComponent = false; } if (!tsmiViewSystemComponent.Checked && siTemp.isSystemComponent) { continue; } // `Name` siTemp.strDisplayName = (string)regkeyTemp.GetValue("DisplayName"); if (siTemp.strDisplayName == null) { continue; } // icon siTemp.strDisplayIcon = (string)regkeyTemp.GetValue("DisplayIcon"); { StringBuilder sbTemp = new StringBuilder(siTemp.strDisplayIcon); PathParseIconLocation(sbTemp); siTemp.strDisplayIcon = sbTemp.ToString(); } // `Publisher` siTemp.strPublisher = (string)regkeyTemp.GetValue("Publisher"); // `Version` siTemp.strDisplayVersion = (string)regkeyTemp.GetValue("DisplayVersion"); // `Installed Time` siTemp.dtLastWriteTime = RegQuery.lastWriteTime(@"HKEY_LOCAL_MACHINE\" + siTemp.strRegistryLocation); string strLastWriteTime = siTemp.dtLastWriteTime.ToString("yyyy-MM-dd HH:mm:ss"); // filepath of uninstaller siTemp.strUninstallString = (string)regkeyTemp.GetValue("UninstallString"); /* * // get realpath * StringBuilder sbQuote = new StringBuilder(siTemp.strUninstallString); * if (!File.Exists(siTemp.strUninstallString)) * PathRemoveArgs(sbQuote); * PathUnquoteSpaces(sbQuote); * StringBuilder sbUninstallString = new StringBuilder(260); * PathSearchAndQualify(sbQuote.ToString(), sbUninstallString, 260); * strUninstallString = sbUninstallString.ToString(); */ // `Help Link` siTemp.strHelpLink = (string)regkeyTemp.GetValue("HelpLink"); // `Support Link` siTemp.strSupportLink = (string)regkeyTemp.GetValue("URLInfoAbout"); // `File Location` siTemp.strFileLocation = (string)regkeyTemp.GetValue("InstallLocation"); if (siTemp.strFileLocation == null) { if (siTemp.strDisplayIcon != null) { siTemp.strFileLocation = FileUtil.DirName(siTemp.strDisplayIcon); } } else { StringBuilder sbTemp = new StringBuilder(siTemp.strFileLocation); PathRemoveBackslash(sbTemp); PathUnquoteSpaces(sbTemp); siTemp.strFileLocation = sbTemp.ToString(); } // `Size` siTemp.lngFileLocationSize = FileUtil.GetDirSize(siTemp.strFileLocation); string strFileLocationSize = siTemp.lngFileLocationSize != -1 ? FileUtil.ConvertHumanReadableFileSize(siTemp.lngFileLocationSize) : null; // search filter if (!((siTemp.strDisplayName != null && StringUtil.InStr(siTemp.strDisplayName, strKeyword)) || (siTemp.strPublisher != null && StringUtil.InStr(siTemp.strPublisher, strKeyword)) || (siTemp.strDisplayVersion != null && StringUtil.InStr(siTemp.strDisplayVersion, strKeyword)) || (strLastWriteTime != null && StringUtil.InStr(strLastWriteTime, strKeyword)) || (strFileLocationSize != null && StringUtil.InStr(strFileLocationSize, strKeyword)))) { continue; } // large icon for preview Icon icoTempLarge = IconReader.GetFileIcon(siTemp.strDisplayIcon, IconReader.IconSize.Large, false); siTemp.imgLargeIcon = icoTempLarge.ToBitmap(); // add listview item ListViewItem lviTemp = new ListViewItem(); lviTemp.Text = siTemp.strDisplayName; // set small icon Icon icoTempSmall = IconReader.GetFileIcon(siTemp.strDisplayIcon, IconReader.IconSize.Small, false); imglstAppSmall.Images.Add(icoTempSmall); lviTemp.ImageIndex = imglstAppSmall.Images.Count - 1; // set subitems if (tsmiViewPublisher.Checked) { lviTemp.SubItems.Add(siTemp.strPublisher); } if (tsmiViewVersion.Checked) { lviTemp.SubItems.Add(siTemp.strDisplayVersion); } if (tsmiViewInstallTime.Checked) { lviTemp.SubItems.Add(strLastWriteTime); } if (tsmiViewSize.Checked) { lviTemp.SubItems.Add(strFileLocationSize); } if (tsmiViewHelpLink.Checked) { lviTemp.SubItems.Add(siTemp.strHelpLink); } if (tsmiViewSupportLink.Checked) { lviTemp.SubItems.Add(siTemp.strSupportLink); } if (tsmiViewFileLocation.Checked) { lviTemp.SubItems.Add(siTemp.strFileLocation); } if (tsmiViewRegistryLocation.Checked) { lviTemp.SubItems.Add(@"HKEY_LOCAL_MACHINE\" + siTemp.strRegistryLocation); } // set backcolor if (isOdd = !isOdd) { lviTemp.BackColor = MyColor.Odd; } else { lviTemp.BackColor = MyColor.Even; } // set forecolor if (!FileUtil.IsDir(siTemp.strFileLocation)) { lviTemp.ForeColor = MyColor.Danger; } // add struct Global.siMain.Add(siTemp); // for access to struct by listview item ListViewUtil.SetSoftwareInformationIndexOfList(lviTemp, Global.siMain.Count - 1); lvApp.Items.Add(lviTemp); lblInstallCount.Text = "Installations : " + lvApp.Items.Count.ToString(); } // sort lblState.Text = "Sorting..."; lvApp.Sorting = soTemp; if (lvApp.Sorting == SortOrder.Ascending) // asc { for (int i = 0; i < lvApp.Columns.Count; i++) { if (lvApp.Columns[i].Text.Contains(" ∧")) { lvApp.ListViewItemSorter = new ListViewItemComparer(i, lvApp.Columns[i].Text.Replace(" ∨", "").Replace(" ∧", ""), SortOrder.Ascending); lvApp.Sorting = SortOrder.Ascending; lvApp.Sort(); break; } } } else if (lvApp.Sorting == SortOrder.Descending) // desc { for (int i = 0; i < lvApp.Columns.Count; i++) { if (lvApp.Columns[i].Text.Contains(" ∨")) { lvApp.ListViewItemSorter = new ListViewItemComparer(i, lvApp.Columns[i].Text.Replace(" ∨", "").Replace(" ∧", ""), SortOrder.Descending); lvApp.Sorting = SortOrder.Descending; lvApp.Sort(); break; } } } // unlock listview ListViewUtil.UnlockUpdate(lvApp); }
public int Compare(object x, object y) { dynamic Value_x = null; dynamic Value_y = null; // listview item to struct index SoftwareInformation siX = ListViewUtil.GetSoftwareInformationOfList((ListViewItem)x, Global.siMain); SoftwareInformation siY = ListViewUtil.GetSoftwareInformationOfList((ListViewItem)y, Global.siMain); // col name to struct info switch (ColumnName) { case "Name": // strDisplayName Value_x = siX.strDisplayName; Value_y = siY.strDisplayName; break; case "Publisher": // strPublisher Value_x = siX.strPublisher; Value_y = siY.strPublisher; break; case "Version": // strDisplayVersion Value_x = siX.strDisplayVersion; Value_y = siY.strDisplayVersion; break; case "Install Time": // dtLastWriteTime Value_x = siX.dtLastWriteTime; Value_y = siY.dtLastWriteTime; break; case "Size": // lngFileLocationSize Value_x = siX.lngFileLocationSize; Value_y = siY.lngFileLocationSize; break; case "Help Link": // strHelpLink Value_x = siX.strHelpLink; Value_y = siY.strHelpLink; break; case "Support Link": // strSupportLink Value_x = siX.strSupportLink; Value_y = siY.strSupportLink; break; case "File Location": // strFileLocation Value_x = siX.strFileLocation; Value_y = siY.strFileLocation; break; case "Registry Location": // strRegistryLocation Value_x = siX.strRegistryLocation; Value_y = siY.strRegistryLocation; break; } if (SortType == SortOrder.Ascending) // asc { if (Value_x is string || Value_x is null) { return(String.Compare((string)Value_x, (string)Value_y)); } else if (Value_x is DateTime) { return(DateTime.Compare((DateTime)Value_x, (DateTime)Value_y)); } else if (Value_x is long) { if (Value_x < Value_y) { return(-1); } else if (Value_x > Value_y) { return(1); } else { return(0); } } else { return(0); } } else if (SortType == SortOrder.Descending) // desc { if (Value_x is string || Value_x is null) { return(String.Compare((string)Value_y, (string)Value_x)); } else if (Value_x is DateTime) { return(DateTime.Compare((DateTime)Value_y, (DateTime)Value_x)); } else if (Value_x is long) { if (Value_x > Value_y) { return(-1); } else if (Value_x < Value_y) { return(1); } else { return(0); } } else { return(0); } } else { //MessageBox.Show("unknown sort type"); return(0); } }