Beispiel #1
0
        private void StatusEvent(object sender, StatusArgs e)
        {
            if (IsDisposed)
            {
                LoggingEnabled = false;
                return;
            }

            if (!mLoggingEnabled)
            {
                return;
            }
            if (InvokeRequired)
            {
                Invoke(new StatusEventDelegate(StatusEvent), new object[] { sender, e });
                return;
            }
            lock (mRtfTextLock)
            {
                if (!ReferenceEquals(mStatusFilterDelegate, null))
                {
                    if (mStatusFilterDelegate(e))
                    {
                        InfWizardStatus.WriteRtfStatusArgsLine(rtfSatus, e);
                    }
                }
                else
                {
                    InfWizardStatus.WriteRtfStatusArgsLine(rtfSatus, e);
                }
            }
        }
Beispiel #2
0
        private static void loadResourcesFromAssembly(Assembly assembly)
        {
            // try loading resources from the executing assembly.
            try
            {
                string[] resourceNames = assembly.GetManifestResourceNames();

                foreach (string resourceName in resourceNames)
                {
                    if (resourceName.ToLower().EndsWith(".driver.resources"))
                    {
                        DriverResource newDriverResource = new DriverResource(assembly.GetManifestResourceStream(resourceName));
                        ResourceList.Add(newDriverResource);
                        InfWizardStatus.Log(CategoryType.DriverResource, StatusType.Info, "{0} loaded", newDriverResource.DisplayName);
                    }
                }
            }
            catch (Exception ex)
            {
                InfWizardStatus.Log(CategoryType.DriverResource,
                                    StatusType.Warning,
                                    "Failed loading driver resources from executing assembly: {0}",
                                    ex.Message);
            }
        }
Beispiel #3
0
        public static bool LoadResources()
        {
            mDriverResourceList = new DriverResourceList();

            DirectoryInfo diApp     = new DirectoryInfo(Path.GetDirectoryName(Application.ExecutablePath));
            DirectoryInfo diCurrent = new DirectoryInfo(Environment.CurrentDirectory);

            System.Collections.Generic.List <String> tempResPathList = new System.Collections.Generic.List <string>();

            tempResPathList.Add(diApp.FullName);
            tempResPathList.Add(diApp.FullName + Path.DirectorySeparatorChar + "DriverResources");
            if (diApp.FullName != diCurrent.FullName)
            {
                tempResPathList.Add(diCurrent.FullName);
                tempResPathList.Add(diCurrent.FullName + Path.DirectorySeparatorChar + "DriverResources");
            }

            foreach (string resPath in tempResPathList)
            {
                loadResourcesFromPath(resPath);
            }

            loadResourcesFromAssembly(Assembly.GetExecutingAssembly());


            if (mDriverResourceList.Count == 0)
            {
                InfWizardStatus.Log(CategoryType.DriverResource, StatusType.Warning, "no resources found");
                InfWizardStatus.Log(CategoryType.DriverResource, StatusType.Warning, resInfWizard.DRIVERRESOURCE_NOTFOUND);
                return(false);
            }

            return(true);
        }
        private void WebClient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            if (IsCancelled)
            {
                mResult = null;
                return;
            }

            try
            {
                mResult = e.Result;
            }
            catch (WebException ex)
            {
                InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "failed getting driver resource list: {0}", ex.Message);
                return;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    if (ex.InnerException is WebException)
                    {
                        InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "download failed: {0}", ex.InnerException.Message);
                        return;
                    }
                }
                InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "download failed: {0}", ex);
            }
            finally
            {
                mDownloadCompleteEvent.Set();
            }
        }
 public void DownloadDataAsync(ProgressBar progressBar, string uri, object userObject)
 {
     try
     {
         lock (mDownloadLock)
         {
             mDownloadCompleteEvent.Reset();
             if (!ReferenceEquals(progressBar, null))
             {
                 progressBar.Style   = ProgressBarStyle.Continuous;
                 progressBar.Minimum = 0;
                 progressBar.Maximum = 100;
                 progressBar.Value   = 0;
             }
             mProgressBar = progressBar;
             mWebClient.DownloadDataAsync(new Uri(uri), userObject);
         }
     }
     catch (WebException ex)
     {
         InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "failed getting driver resource list: {0}", ex.Message);
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null)
         {
             if (ex.InnerException is WebException)
             {
                 InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "failed getting driver resource list: {0}", ex.InnerException.Message);
                 return;
             }
         }
         InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "failed getting driver resource list: {0}", ex);
     }
 }
Beispiel #6
0
        public static bool InstallSetupPackage(string hardwareId, string infPath)
        {
            bool bSuccess = SetupApi.UpdateDriverForPlugAndPlayDevices(IntPtr.Zero,
                                                                       hardwareId,
                                                                       infPath,
                                                                       SetupApi.INSTALLFLAG.FORCE,
                                                                       IntPtr.Zero);

            if (bSuccess)
            {
                InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Success, "driver update completed");
                UpdateDriver(hardwareId);
                return(true);
            }

            // UpdateDriverForPlugAndPlayDevices FAILED
            ECODE setupError = (ECODE)Marshal.GetLastWin32Error();

            if (setupError != ECODE.NO_SUCH_DEVINST)
            {
                InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Win32Error, "UpdateDriverForPlugAndPlayDevices failed");
                return(false);
            }
            // UpdateDriverForPlugAndPlayDevices = NO_SUCH_DEVINST
            InfWizardStatus.Log(CategoryType.InstallSetupPackage,
                                StatusType.Warning,
                                "device not detected (copying driver files for next time device is plugged in)");

            StringBuilder sbDestInfFilename = new StringBuilder(1024);
            uint          requiredSize;

            bSuccess = SetupApi.SetupCopyOEMInf(infPath,
                                                null,
                                                SetupApi.SPOST.SPOST_PATH,
                                                0,
                                                sbDestInfFilename,
                                                (uint)sbDestInfFilename.Capacity,
                                                out requiredSize,
                                                null);

            if (!bSuccess)
            {
                InfWizardStatus.Log(CategoryType.InstallSetupPackage,
                                    StatusType.Win32Error,
                                    "SetupCopyOEMInf failed");
            }
            else
            {
                InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Success, "copied inf to {0}", sbDestInfFilename.ToString());
            }
            CheckRemoved(hardwareId);
            return(bSuccess);
        }
Beispiel #7
0
        private static void loadResourcesFromPath(string path)
        {
            // try loading resources from the working directory.
            try
            {
                if (!Directory.Exists(path))
                {
                    return;
                }

#if DEBUG
                InfWizardStatus.Log(CategoryType.DriverResource, StatusType.Info, "loading resource(s) from {0}", path);
#endif
                string[] files = Directory.GetFiles(path, "*.driver.resources");
                foreach (string file in files)
                {
                    DriverResource newDriverResource = new DriverResource(file);
                    if (!ResourceList.Add(newDriverResource))
                    {
#if DEBUG
                        InfWizardStatus.Log(CategoryType.DriverResource,
                                            StatusType.Warning,
                                            "skipping duplicate driver resource {0} found in {1}",
                                            newDriverResource.DisplayName,
                                            file);
#endif
                    }
                    else
                    {
                        InfWizardStatus.Log(CategoryType.DriverResource, StatusType.Info, "{0} loaded", newDriverResource.DisplayName);
                    }
                }
                if (ResourceList.Count > 0)
                {
                    return;
                }
            }
            catch (Exception ex)
            {
                InfWizardStatus.Log(CategoryType.DriverResource, StatusType.Info, "failed loading driver resources from working directory :{0}", ex.ToString());
            }
            return;
        }
Beispiel #8
0
        private void InstallSetupPackageFn(object state)
        {
            Thread.Sleep(0);
            rtfFinishedSatus.LoggingEnabled = true;

            InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Info, "installing driver, please wait..");

            bool success = Wdi.InstallSetupPackage(mCurrentDeviceItem.BuildInfHardwareID(), mCurrentInfWriter.GetDriverPathFilename("inf"));

            if (success)
            {
                InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Success, "driver installed successfully");
            }
            else
            {
                InfWizardStatus.Log(CategoryType.InstallSetupPackage, StatusType.Error, "driver install failed");
            }

            rtfFinishedSatus.LoggingEnabled = false;
            Invoke(new GenericStateDelegate(InstallSetupPackageCompleteFn), new object[] { success });
        }
Beispiel #9
0
        private void RawStatusEvent(object sender, RawStatusArgs rawArgs)
        {
            if (IsDisposed)
            {
                LoggingEnabled = false;
                return;
            }

            if (!mLoggingEnabled)
            {
                return;
            }
            if (InvokeRequired)
            {
                Invoke(new RawStatusEventDelegate(RawStatusEvent), new object[] { sender, rawArgs });
                return;
            }
            lock (mRtfTextLock)
            {
                InfWizardStatus.WriteRtfRawStatus(rtfSatus, rawArgs.RawData);
            }
        }
Beispiel #10
0
        private void Remove()
        {
            DEIFlags flags = DEIFlags.DICFG_AllClasses | DEIFlags.IncludeWindowsServices;

            Cursor = Cursors.WaitCursor;

            rtfRemoveDeviceStatus.StatusFilter = RemoveStatusFilter;
            removeDeviceOptionGrid.Enabled     = false;
            removeCommand.Enabled = false;

            if (DefaultRemoveOptions.OnlyConnectedDevices)
            {
                flags = flags | DEIFlags.DICFG_Present;
            }

            try
            {
                mRemoveDialogResult = DialogResult.OK;
                rtfRemoveDeviceStatus.LoggingEnabled = true;
                InfWizardStatus.Log(CategoryType.RemoveDevice, StatusType.Info, "enumerating devices..");
                DeviceSelectionHelper.RemoveDevice(DefaultRemoveOptions, Handle, flags);

                if (DefaultRemoveOptions.DeepClean)
                {
                    DeepClean();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "Device Removal", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                rtfRemoveDeviceStatus.LoggingEnabled = false;
                Cursor = Cursors.Default;
                removeDeviceOptionGrid.Enabled = true;
            }
        }
        private void downloadDriverResources()
        {
            bool success = false;

            groupBoxDriverList.Enabled      = false;
            buttonCancelDownload.Enabled    = false;
            groupBoxDownloadStatus.Enabled  = true;
            rtfDownloadSatus.LoggingEnabled = true;
            driverResourceDownloader.Reset();

            try
            {
                DriverResourceDownloads resourceDownloads = new DriverResourceDownloads();
                foreach (DataGridViewRow selectedRow in dataGridViewDriverDownloadList.SelectedRows)
                {
                    resourceDownloads.Add(selectedRow.Tag as DriverResourceDownload);
                }

                int waitRet = -1;
                foreach (DriverResourceDownload resourceDownload in resourceDownloads)
                {
                    if (driverResourceDownloader.IsCancelled)
                    {
                        waitRet = 1;
                        break;
                    }
                    InfWizardStatus.Log(CategoryType.DriverDownloader,
                                        StatusType.Info,
                                        "requesting driver resource {0}..",
                                        resourceDownload.DisplayName);

                    progressBarDownloadDriverResources.Value = 0;
                    driverResourceDownloader.DownloadDataAsync(progressBarDownloadDriverResources, resourceDownload.Url, null);
                    buttonCancelDownload.Enabled = true;

                    WaitHandle[] waitHandles = new WaitHandle[]
                    { driverResourceDownloader.CompleteWaitHandle, driverResourceDownloader.CancelWaitHandle };
                    do
                    {
                        waitRet = WaitHandle.WaitAny(waitHandles, 10);
                        Application.DoEvents();
                        Thread.Sleep(0);
                    } while (waitRet == WaitHandle.WaitTimeout);

                    switch (waitRet)
                    {
                    case 0:
                        InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Info, "driver resource downloaded.");
                        break;

                    case 1:
                        InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Warning, "failed getting driver resource; operation cancelled.");
                        break;

                    case WaitHandle.WaitTimeout:
                        InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "connection timed out.");
                        break;
                    }
                    if (waitRet == 0 && driverResourceDownloader.Result != null)
                    {
                        string downloadFilename = driverResourceDownloader.GetDownloadFilename();

                        // TODO: Add main driver resource path for saving downloaded resources
                        string path = null;
                        if (String.IsNullOrEmpty(path))
                        {
                            path = Environment.CurrentDirectory;
                        }

                        string resourceFilename = Path.Combine(path, downloadFilename);
                        if (File.Exists(resourceFilename))
                        {
                            InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Warning, "deleting driver resource file {0}", resourceFilename);
                            File.Delete(resourceFilename);
                        }
                        InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Success, "saving driver resource {0}", resourceFilename);
                        FileStream resourceStreamOut = File.Create(resourceFilename);
                        resourceStreamOut.Write(driverResourceDownloader.Result, 0, driverResourceDownloader.Result.Length);
                        resourceStreamOut.Flush();
                        resourceStreamOut.Close();
                    }
                    else
                    {
                        break;
                    }
                }

                if (waitRet == 0)
                {
                    if (DriverResManager.LoadResources())
                    {
                        success = true;
                    }
                    else
                    {
                        InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "failed loading driver resources!");
                    }
                }
            }
            catch (Exception ex)
            {
                InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, ex.ToString());
                buttonDownloadDriverResources.Enabled = false;
                success = false;
            }
            finally
            {
                buttonCancelDownload.Enabled    = false;
                rtfDownloadSatus.LoggingEnabled = false;
                if (success)
                {
                    buttonSelectAllDriverResources_Click(this, new EventArgs());
                    wizMain.NextEnabled = DriverResManager.Check();
                }
                groupBoxDriverList.Enabled = true;
            }
        }
        private void downloadDriverResourceList()
        {
            bool success = false;

            groupBoxDriverList.Enabled      = false;
            buttonCancelDownload.Enabled    = false;
            groupBoxDownloadStatus.Enabled  = true;
            rtfDownloadSatus.LoggingEnabled = true;
            driverResourceDownloader.Reset();

            try
            {
                InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Info, "requesting driver resource list..");

                dataGridViewDriverDownloadList.Rows.Clear();

                driverResourceDownloader.DownloadDataAsync(progressBarDownloadDriverResources, mSettings.DriverResourceUrl, null);
                buttonCancelDownload.Enabled = true;
                int          waitRet;
                WaitHandle[] waitHandles = new WaitHandle[] { driverResourceDownloader.CompleteWaitHandle, driverResourceDownloader.CancelWaitHandle };
                do
                {
                    waitRet = WaitHandle.WaitAny(waitHandles, 10);
                    Application.DoEvents();
                    Thread.Sleep(0);
                } while (waitRet == WaitHandle.WaitTimeout);


                switch (waitRet)
                {
                case 0:
                    break;

                case 1:
                    InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Warning, "get driver resource list cancelled.");
                    break;

                case WaitHandle.WaitTimeout:
                    InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "get driver resource list connection timed out.");
                    break;
                }
                if (waitRet == 0 && driverResourceDownloader.Result != null)
                {
                    MemoryStream            resultStream            = new MemoryStream(driverResourceDownloader.Result);
                    DriverResourceDownloads driverResourceDownloads = DriverResourceDownloads.Load(resultStream);

                    if (driverResourceDownloads != null)
                    {
                        foreach (DriverResourceDownload download in driverResourceDownloads)
                        {
                            int row = dataGridViewDriverDownloadList.Rows.Add(new object[] { download.DisplayName, download.Description });
                            dataGridViewDriverDownloadList.Rows[row].Tag = download;
                        }

                        success = true;
                        InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Success, "get driver resource list complete.");
                        resultStream.Seek(0, SeekOrigin.Begin);
                        try
                        {
                            string fileName = driverResourceDownloader.GetDownloadFilename();
                            File.WriteAllBytes(fileName, driverResourceDownloader.Result);
                        }
                        catch (Exception)
                        {}
                    }

                    if (!success)
                    {
                        InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, "invalid driver resource list.");
                    }
                }
            }
            catch (Exception ex)
            {
                InfWizardStatus.Log(CategoryType.DriverDownloader, StatusType.Error, ex.ToString());
                success = false;
            }
            finally
            {
                buttonCancelDownload.Enabled    = false;
                rtfDownloadSatus.LoggingEnabled = false;
                if (success)
                {
                    groupBoxDriverList.Enabled = true;
                    SynchronizationContext.Current.Post(selectDriverResources, true);
                }
            }
        }
Beispiel #13
0
        /// <summary>
        /// Force re-enumeration of a device (force installation)
        /// TODO: allow root re-enum
        /// </summary>
        public static int UpdateDriver(string deviceHardwareID)
        {
            int  devIndex;
            int  refreshed = 0;
            bool bSuccess;

            // Initialize the SP_DEVINFO_DATA structure
            SetupApi.SP_DEVINFO_DATA devInfoData = new SetupApi.SP_DEVINFO_DATA();

            // List all connected USB devices
            IntPtr pDevInfo = SetupApi.SetupDiGetClassDevs(0, "USB", IntPtr.Zero, SetupApi.DICFG.ALLCLASSES);

            if (pDevInfo == IntPtr.Zero || pDevInfo == new IntPtr(-1))
            {
                return(refreshed);
            }
            for (devIndex = 0;; devIndex++)
            {
                devInfoData.cbSize = (uint)Marshal.SizeOf(typeof(SetupApi.SP_DEVINFO_DATA));
                bSuccess           = SetupApi.SetupDiEnumDeviceInfo(pDevInfo, devIndex, ref devInfoData);

                // Reached the end of the deviceInfo list.
                if (!bSuccess)
                {
                    break;
                }

                // Find the hardware ID
                string[] saHardwareIDs;
                bSuccess = SetupApi.SetupDiGetDeviceRegistryProperty(out saHardwareIDs,
                                                                     pDevInfo,
                                                                     ref devInfoData,
                                                                     SetupApi.SPDRP.HARDWAREID);

                // Failed getting hardware id
                if (!bSuccess)
                {
                    break;
                }

                // Failed getting hardware id
                if (saHardwareIDs.Length == 0)
                {
                    continue;
                }

                // Check all hardwareids for a match
                bool bFound = false;
                foreach (string s in saHardwareIDs)
                {
                    if (s.Trim().ToLower() == deviceHardwareID.Trim().ToLower())
                    {
                        bFound = true;
                        break;
                    }
                }

                // Hardware did not match; goto next device
                if (!bFound)
                {
                    continue;
                }

                // Re-enumerate the device node
                SetupApi.CR status = SetupApi.CM_Reenumerate_DevNode((int)devInfoData.DevInst,
                                                                     SetupApi.CM.REENUMERATE_RETRY_INSTALLATION);
                if (status == SetupApi.CR.SUCCESS)
                {
                    InfWizardStatus.Log(CategoryType.RefreshDriver, StatusType.Success, "re-enumeration of {0} succeeded...", deviceHardwareID);
                }
                else if (status == SetupApi.CR.INVALID_DEVNODE)
                {
                    continue;
                }
                else
                {
                    InfWizardStatus.Log(CategoryType.RefreshDriver, StatusType.Warning, "failed to re-enumerate device node: CR code {0}", status);
                    continue;
                }



                refreshed++;
            }
            // return the number of devices that were re-enumerated.
            return(refreshed);
        }
Beispiel #14
0
        /// <summary>
        /// Flag phantom/removed devices for reinstallation.
        /// See: http://msdn.microsoft.com/en-us/library/aa906206.aspx
        /// </summary>
        public static int CheckRemoved(string deviceHardwareID)
        {
            int  devIndex;
            int  removed = 0;
            bool bSuccess;

            // Initialize the SP_DEVINFO_DATA structure
            SetupApi.SP_DEVINFO_DATA devInfoData = new SetupApi.SP_DEVINFO_DATA();
            devInfoData.cbSize = (uint)Marshal.SizeOf(typeof(SetupApi.SP_DEVINFO_DATA));

            // List all connected USB devices
            IntPtr pDevInfo = SetupApi.SetupDiGetClassDevs(0, "USB", IntPtr.Zero, SetupApi.DICFG.ALLCLASSES);

            if (pDevInfo == IntPtr.Zero || pDevInfo == new IntPtr(-1))
            {
                return(removed);
            }
            for (devIndex = 0;; devIndex++)
            {
                bSuccess = SetupApi.SetupDiEnumDeviceInfo(pDevInfo, devIndex, ref devInfoData);

                // Reached the end of the deviceInfo list.
                if (!bSuccess)
                {
                    break;
                }

                // Find the hardware ID
                string[] saHardwareIDs;
                bSuccess = SetupApi.SetupDiGetDeviceRegistryProperty(out saHardwareIDs,
                                                                     pDevInfo,
                                                                     ref devInfoData,
                                                                     SetupApi.SPDRP.HARDWAREID);

                // Failed getting hardware id
                if (!bSuccess)
                {
                    break;
                }

                // Failed getting hardware id
                if (saHardwareIDs.Length == 0)
                {
                    continue;
                }

                // Check all hardwareids for a match
                bool bFound = false;
                foreach (string s in saHardwareIDs)
                {
                    if (s.Trim().ToLower() == deviceHardwareID.Trim().ToLower())
                    {
                        bFound = true;
                        break;
                    }
                }

                // Hardware did not match; goto next device
                if (!bFound)
                {
                    continue;
                }

                uint status;
                uint pbmNumber;

                // If not Unplugged.
                bSuccess = (SetupApi.CM_Get_DevNode_Status(out status, out pbmNumber, devInfoData.DevInst, 0) == SetupApi.CR.NO_SUCH_DEVNODE);
                if (!bSuccess)
                {
                    continue;
                }

                // Flag for reinstall on next plugin
                uint configFlags;
                bSuccess = SetupApi.SetupDiGetDeviceRegistryProperty(out configFlags, pDevInfo, ref devInfoData, SetupApi.SPDRP.CONFIGFLAGS);
                if (!bSuccess)
                {
                    InfWizardStatus.Log(CategoryType.CheckRemoved,
                                        StatusType.Warning,
                                        "could not read SPDRP_CONFIGFLAGS for phantom device {0}",
                                        deviceHardwareID);
                    continue;
                }

                // Mark for re-installation
                configFlags |= (uint)SetupApi.CONFIGFLAG.REINSTALL;
                uint[] flags = new uint[] { configFlags };
                bSuccess = SetupApi.SetupDiSetDeviceRegistryProperty(pDevInfo,
                                                                     ref devInfoData,
                                                                     SetupApi.SPDRP.CONFIGFLAGS,
                                                                     flags,
                                                                     Marshal.SizeOf(typeof(uint)));
                if (!bSuccess)
                {
                    InfWizardStatus.Log(CategoryType.CheckRemoved,
                                        StatusType.Warning,
                                        "could not write SPDRP_CONFIGFLAGS for phantom device {0}",
                                        deviceHardwareID);
                    continue;
                }
                removed++;
            }

            if (removed > 0)
            {
                InfWizardStatus.Log(CategoryType.CheckRemoved, StatusType.Info, "flagged {0} removed devices for reinstallation", removed);
            }

            SetupApi.SetupDiDestroyDeviceInfoList(pDevInfo);

            return(removed);
        }
Beispiel #15
0
        private void writeSetupPackageCompletedFn(object state)
        {
            if (mSetupPackageWritten)
            {
                rtfFinishedSatus.LoggingEnabled = true;
                foreach (DeviceItem deviceItem in mFoundLikeDevices)
                {
                    string connected   = deviceItem.IsConnected ? "connected" : "unplugged";
                    string driverless  = deviceItem.IsDriverless ? "without a driver" : "with a driver";
                    string description = deviceItem.DeviceDescription;
                    if (!deviceItem.mDriverless)
                    {
                        mCurrentDeviceItem.mDriverless = false;
                        if (deviceItem.IsConnected)
                        {
                            mCurrentDeviceItem.mDeviceId    = deviceItem.mDeviceId;
                            mCurrentDeviceItem.mIsConnected = true;
                        }
                        if (!String.IsNullOrEmpty(deviceItem.mServiceName))
                        {
                            mCurrentDeviceItem.mServiceName = deviceItem.mServiceName;
                        }
                    }

                    Color customColor = deviceItem.mDriverless ? Color.DarkBlue : Color.DarkOrange;
                    if (deviceItem.mIsSkipServiceName)
                    {
                        customColor = Color.DarkRed;
                    }
                    string serviceName = String.IsNullOrEmpty(deviceItem.mServiceName) ? "" : " (" + deviceItem.mServiceName + ")";

                    object[] customLog = new object[]
                    {
                        "\n", FontStyle.Bold, customColor, "InstallCheck", Color.Black, " :\t", FontStyle.Regular, description, serviceName, "\n",
                        "\t\tfound ", connected, " device ", driverless, " (", deviceItem.mDeviceId.Substring(4), ")\n"
                    };
                    InfWizardStatus.LogRaw(customLog);

                    //InfWizardStatus.Log(CategoryType.EnumerateDevices,
                    //                    deviceItem.IsConnected && !deviceItem.mDriverless ? StatusType.Warning : StatusType.Info,
                    //                    "found {0} {1} device {2} matching {3}",
                    //                    connected,
                    //                    driverless,
                    //                    description,
                    //                    currentHardwareID.Substring(4));
                }
                List <DeviceItem> driverlessList  = mFoundLikeDevices.FindAll(DeviceItem.FindDriverlessPredicate);
                List <DeviceItem> skipServiceList = mFoundLikeDevices.FindAll(DeviceItem.FindSkipServicePredicate);

                if (driverlessList.Count == mFoundLikeDevices.Count)
                {
                    mCurrentDeviceItem.mDriverless = true;
                }
                if (mFoundLikeDevices.Count == 0)
                {
                    mCurrentDeviceItem.mDriverless = true;
                }

                if (skipServiceList.Count > 0)
                {
                    pictureBoxInstallDriver.Image = resInfWizard.StopImage;
                    labelInstallDriver.Text       = String.Format(resInfWizard.INSTALLDRIVER_WINDOWSSERVICE_TEXT, mCurrentDeviceItem.mServiceName);
                    buttonInstallDriver.Enabled   = false;
                }
                else if ((mCurrentDeviceItem.mDriverless))
                {
                    pictureBoxInstallDriver.Image = resInfWizard.InfoImage;
                    labelInstallDriver.Text       = resInfWizard.INSTALLDRIVER_DRIVERLESS_TEXT;
                    buttonInstallDriver.Enabled   = true;
                }
                else
                {
                    pictureBoxInstallDriver.Image = resInfWizard.YieldImage;
                    labelInstallDriver.Text       = String.Format(resInfWizard.INSTALLDRIVER_UPDATE_TEXT, mCurrentDeviceItem.mServiceName);
                    buttonInstallDriver.Enabled   = true;
                }
            }
            else
            {
                pictureBoxInstallDriver.Image = resInfWizard.StopImage;
                labelInstallDriver.Text       = resInfWizard.INSTALLDRIVER_NOPACKAGE_TEXT;
                buttonInstallDriver.Enabled   = false;
            }
            rtfFinishedSatus.LoggingEnabled = false;

            wizardPageFinishedEnable(true);
        }