Exemplo n.º 1
0
        private void tsmiOpenFile_Click(object sender, EventArgs e)
        {
            if (lvApp.SelectedItems.Count < 1)
            {
                return;
            }

            foreach (ListViewItem lviTemp in lvApp.SelectedItems)
            {
                SoftwareInformation siTemp = ListViewUtil.GetSoftwareInformationOfList(lviTemp, Global.siMain);

                Process.Start("explorer.exe", siTemp.strFileLocation);
            }
        }
Exemplo n.º 2
0
        private void lvApp_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvApp.SelectedItems.Count < 1)
            {
                return;
            }

            SoftwareInformation siTemp = ListViewUtil.GetSoftwareInformationOfList(lvApp.SelectedItems[0], Global.siMain);

            picAppIcon.Image = siTemp.imgLargeIcon;

            lblDisplayName.Text = siTemp.strDisplayName;
            lblPublisher.Text   = siTemp.strPublisher;

            lblState.Text = "Selected " + lvApp.SelectedItems.Count.ToString() + " item" + (lvApp.SelectedItems.Count > 1 ? "s" : "") + ".";
        }
Exemplo n.º 3
0
        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");
            }
        }
Exemplo n.º 4
0
        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.";
                }
            }
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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);
            }
        }