Example #1
0
        /// <summary>
        /// call to SDK for driver update function
        /// </summary>
        /// <param name="arrUserDrivers"></param>
        /// <param name="arrUserUpdates"></param>
        public int UpdateDrivers(DriverData[] arrUserDrivers, DriverData[] arrUserUpdates)
        {
            //bDriverUpdateIsGoingOn = true;
            int retval = 0;
            IntPtr pUnmanagedUserDrivers = IntPtr.Zero;
            IntPtr pUnmanagedUserUpdates = IntPtr.Zero;

            try
            {
                // marshal input
                pUnmanagedUserDrivers = MarshalHelper.MarshalArray(ref arrUserDrivers);
                pUnmanagedUserUpdates = MarshalHelper.MarshalArray(ref arrUserUpdates);

                // call driver update function
                retval = DUSDKHandler.updateDeviceDriversEx(
                    progressCallback,
                    szProductKey,
                    szAppDataLoc,
                    szTempLoc,
                    szRegistryLoc,
                    downloadProgressCallback,
                    pUnmanagedUserDrivers,
                    pUnmanagedUserUpdates,
                    arrUserDrivers.Length,
                    szRestorePointName
                    );


                if (retval == DUSDKHandler.DefineConstants.SUCCESS)
                {
                    //this.UIThread(() => this.label3.Text = "Drivers Updated Successfully!!");
                }
                else if (retval == DUSDKHandler.DefineConstants.CANCEL_INSTALL)
                {
                    //this.UIThread(() => this.label3.Text = "Update Stopped Successfully!!");
                }
                else if (retval == DUSDKHandler.DefineConstants.FAIL)
                {
                    ScanStatusTitle = WPFLocalizeExtensionHelpers.GetUIString("UpdateFailed");
                    ScanStatusText = string.Empty;
                }
                else
                {
                    ; // check for error code
                }

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                // free memory
                if (pUnmanagedUserDrivers != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pUnmanagedUserDrivers);
                }

                if (pUnmanagedUserUpdates != IntPtr.Zero)
                {
                    Marshal.FreeHGlobal(pUnmanagedUserUpdates);
                }

                pUnmanagedUserDrivers = IntPtr.Zero;
                pUnmanagedUserUpdates = IntPtr.Zero;

                bDriverUpdateIsGoingOn = false;
            }

            return retval;
        }
Example #2
0
        void DriverUpdate(object sender, DoWorkEventArgs e)
        {
            bDriverUpdateIsGoingOn = true;
            devicesForUpdate = DevicesForScanning.Where(d => d.NeedsUpdate && d.SelectedForUpdate).ToList();

            DriverData[] scanData = new DriverData[devicesForUpdate.Count];
            DriverData[] updateData = new DriverData[devicesForUpdate.Count];

            int i = 0;
            int id;

            foreach (DeviceInfo di in devicesForUpdate)
            {
                if (Int32.TryParse(di.Id, out id))
                {
                    scanData[i] = driverData[id];
                    updateData[i] = UserUpdates[id];
                    i++;
                }
            }

            UpdateDrivers(scanData, updateData);

            scanData = null;
            updateData = null;
        }