private void buttonDelete_Click(object sender, EventArgs e)
        {
            if (lstDriverStoreEntries.CheckedObjects.Count == 0 && lstDriverStoreEntries.SelectedIndex == -1)
            {
                // No entry is selected 
                ShowStatus("Select a driver entry first", Status.Warning);
                return;
            }

            DriverStoreEntry dse = new DriverStoreEntry();  // for appeasing the compiler!
            List<DriverStoreEntry> ldse = new List<DriverStoreEntry>();
            string msgWarning = "";
            bool fMultiPackageDeletion = false;
            if (lstDriverStoreEntries.CheckedObjects.Count == 0)
            {
               dse = (DriverStoreEntry)lstDriverStoreEntries.GetSelectedObject();
               msgWarning = String.Format("About to {0} {1} from driver store.\nAre you sure?", 
                                            cbForceDeletion.Checked == true ? "force delete" : "delete", 
                                            dse.driverPublishedName
                                            );
            }
            else
            {
                if (lstDriverStoreEntries.CheckedItems.Count > 0)
                {
                    //string s = "";                    
                    foreach (DriverStoreEntry o in lstDriverStoreEntries.CheckedObjects)
                    {
                        //s += o.driverPublishedName + "\n";
                        ldse.Add(o);
                    }
                    //MessageBox.Show(s);
                    fMultiPackageDeletion = true;
                    msgWarning = String.Format("About to {0} {1} packages from driver store.\nAre you sure?",
                                            cbForceDeletion.Checked == true ? "force delete" : "delete",
                                            ldse.Count
                                            );
                }
                else
                {
                    throw new Exception("Unknown state - CP100");   //Checkpoint - CP100
                }
            }
            if (DialogResult.OK == MessageBox.Show
                                (msgWarning, 
                                "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
                                )
            {                
                if (fMultiPackageDeletion == false)
                    DeleteDriverPackage(dse);
                else
                    DeleteDriverPackages(ldse);
            }
        }
        private void DeleteDriverPackage(DriverStoreEntry dse)
        {
            if (!(backgroundWorker1.IsBusy))
            {
                CleanupContext(context);
                context.code = cbForceDeletion.Checked == true ? OperationCode.ForceDeleteDriver : OperationCode.DeleteDriver;
                context.dse = dse;

                context.IsCollectionPassed = false;
                context.ldse = null;

                backgroundWorker1.RunWorkerAsync(context);

                ShowOperationInProgress(true);
                ShowStatus("Deleting driver package...");
            }
            else
            {
                MessageBox.Show("Another operation in progress");
                ShowStatus("Ready");
            }
        }
Exemple #3
0
        public static List <DriverStoreEntry> ParsePnpUtilEnumerateResult(string pnpUtilOutput)
        {
            List <DriverStoreEntry> driverStoreEntries = new List <DriverStoreEntry>();

            using (StringReader sr = new StringReader(pnpUtilOutput))
            {
                DriverStoreEntry driverStoreEntry = new DriverStoreEntry();
                string           currentLine;
                bool             sawKey = false;
                ParsingState     state  = ParsingState.Header;

                while ((currentLine = sr.ReadLine()) != null)
                {
                    if (state == ParsingState.Header)
                    {
                        // We're expecting a header. Blank line marks the end of the header.
                        if (currentLine.Length == 0)
                        {
                            state = ParsingState.PublishedName;
                        }

                        continue;
                    }
                    else if (currentLine.Length == 0)
                    {
                        // Blank line means the end of an driver entry.
                        if (!driverStoreEntry.Equals(default(DriverStoreEntry)))
                        {
                            driverStoreEntries.Add(driverStoreEntry);
                            driverStoreEntry = new DriverStoreEntry();
                        }

                        // The next line should be driver OEM INF name.
                        state  = ParsingState.PublishedName;
                        sawKey = false;
                        continue;
                    }
                    else
                    {
                        bool   finishProcessCurrentLine = false;
                        string value = null;
                        bool   hasKeyValueDelimiter = currentLine.IndexOf(':') != -1;

                        if (hasKeyValueDelimiter)
                        {
                            string[] currentLineDivided = currentLine.Split(NameValueDelimiter, 2);

                            if (currentLineDivided.Length > 1)
                            {
                                value = currentLineDivided[1].Trim();
                            }
                        }
                        else
                        {
                            value = currentLine.Trim();
                        }

                        if (state == ParsingState.PublishedName)
                        {
                            driverStoreEntry.DriverPublishedName = GetDriverPropAndUpdateParsingState(value, hasKeyValueDelimiter, ParsingState.PkgProvider, out finishProcessCurrentLine, ref sawKey, ref state);

                            if (finishProcessCurrentLine)
                            {
                                continue;
                            }
                        }

                        if (state == ParsingState.PkgProvider)
                        {
                            driverStoreEntry.DriverPkgProvider = GetDriverPropAndUpdateParsingState(value, hasKeyValueDelimiter, ParsingState.Class, out finishProcessCurrentLine, ref sawKey, ref state);

                            if (finishProcessCurrentLine)
                            {
                                continue;
                            }
                        }

                        if (state == ParsingState.Class)
                        {
                            driverStoreEntry.DriverClass = GetDriverPropAndUpdateParsingState(value, hasKeyValueDelimiter, ParsingState.DriverDateVersion, out finishProcessCurrentLine, ref sawKey, ref state);

                            if (finishProcessCurrentLine)
                            {
                                continue;
                            }
                        }

                        if (state == ParsingState.DriverDateVersion)
                        {
                            driverStoreEntry.SetDriverDateAndVersion(GetDriverPropAndUpdateParsingState(value, hasKeyValueDelimiter, ParsingState.Signer, out finishProcessCurrentLine, ref sawKey, ref state));

                            if (finishProcessCurrentLine)
                            {
                                continue;
                            }
                        }

                        if (state == ParsingState.Signer)
                        {
                            driverStoreEntry.DriverSignerName = GetDriverPropAndUpdateParsingState(value, hasKeyValueDelimiter, ParsingState.PublishedName, out finishProcessCurrentLine, ref sawKey, ref state);

                            if (finishProcessCurrentLine)
                            {
                                continue;
                            }
                        }
                    }
                }

                if (!string.IsNullOrEmpty(driverStoreEntry.DriverPublishedName))
                {
                    driverStoreEntries.Add(driverStoreEntry);
                }
            }

            return(driverStoreEntries);
        }
 public bool DeletePackage(DriverStoreEntry dse, bool forceDelete)
 {
     string dummy = "";
     return PnpUtilHelper(forceDelete == true ? PnpUtilOptions.ForceDelete : PnpUtilOptions.Delete,
                   dse.driverPublishedName, 
                   ref dummy);
 }
        public List<DriverStoreEntry> EnumeratePackages()
        {
            List<DriverStoreEntry> ldse = new List<DriverStoreEntry>();
            string output = ""; 

            bool result = PnpUtilHelper(PnpUtilOptions.Enumerate, "",  ref output);
            if (result == true)
            {                
                // Trace.TraceInformation("O/P of Enumeration : " + Environment.NewLine + output + Environment.NewLine);

                // Parse the output
                // [jenda_] Didn't work on non-english Windows - changed from string recognition to counting lines
                using (StringReader sr = new StringReader(output))                
                {
                    string currentLine = "";
                    string[] currentLineDivided = { };
                    DriverStoreEntry dse = new DriverStoreEntry();
                    byte lineNum = 0;
                    while ((currentLine = sr.ReadLine()) != null)
                    {
                        currentLineDivided = currentLine.Split(new char[] { ':' });
                        if (currentLineDivided.Length == 2)
                        {
                            currentLineDivided[1] = currentLineDivided[1].Trim();
                            if (currentLineDivided[1] == "")
                                currentLineDivided[1] = sr.ReadLine();
                            if (currentLineDivided[1] == null)
                                break;
                            currentLineDivided[1] = currentLineDivided[1].Trim();

                            switch (lineNum)
                            {
                                case 0:     // [jenda_] Published name :
                                    dse.driverPublishedName = currentLineDivided[1];
                                    break;
                                case 1:     //Driver package provider :
                                    dse.driverPkgProvider = currentLineDivided[1];
                                    break;
                                case 2:     // [jenda_] Class :
                                    dse.driverClass = currentLineDivided[1];
                                    break;
                                case 3:     // [jenda_] Driver date and version :
                                    string DateAndVersion = currentLineDivided[1];
                                    dse.driverDate = DateAndVersion.Split(new char[] { ' ' })[0].Trim();
                                    dse.driverVersion = DateAndVersion.Split(new char[] { ' ' })[1].Trim();
                                    break;
                                case 4:     // [jenda_] Signer name :
                                    dse.driverSignerName = currentLineDivided[1];

                                    ldse.Add(dse);
                                    dse = new DriverStoreEntry();
                                    break;
                                default:
                                    continue;
                            }
                            lineNum++;
                            if (lineNum > 4)
                                lineNum = 0;

                        }
                    }
                }

            }
            return ldse;
        }