예제 #1
0
        public void InstallDrivers(string[] dirs)
        {
            string infFile = null;

            foreach (string dir in dirs)
            {
                try
                {
#if EUCA_DEBUG
                    LogTools.Debug(string.Format("Attemping to install driver {0}", dir));
#endif
                    string[] infs = Directory.GetFiles(dir, "*.inf");
                    if (infs == null || infs.Length == 0)
                    {
                        Program.Log(string.Format("Can't find 'inf' file in {0}", dir));
                        continue;
                    }
                    if (infs.Length > 1)
                    {
                        Program.Log(string.Format("[WARNING] There are more than one 'inf' files in {0}", dir));
                    }
                    infFile = infs[0];

                    StringBuilder destFile = new StringBuilder(MAX_PATH);
                    int           reqSize  = 0;
                    StringBuilder destinationInfFileNameComponent = new StringBuilder();
                    bool          copied = SetupCopyOEMInf(infFile, null, OemSourceMediaType.SPOST_PATH,
                                                           OemCopyStyle.SP_COPY_NOOVERWRITE | OemCopyStyle.SP_COPY_FORCE_IN_USE,
                                                           destFile, MAX_PATH, ref reqSize, destinationInfFileNameComponent);

                    if (copied)
                    {
                        Program.Log(string.Format("The driver({0}) succesfully installed", infFile));
                    }
                    else
                    {
                        int errCode = GetLastError();
                        if (errCode == ERROR_FILE_EXISTS)
                        {
                            Program.Log(string.Format("The driver({0}) already found in the system", infFile));
                        }
                        else
                        {
                            throw new Exception(string.Format("SetupCopyOEMInf on {0} returned error code ({1})", infFile, errCode));
                        }
                    }
                }
                catch (Exception e)
                {
                    Program.Log(e.Message);
                    Program.Log(e.StackTrace);
                    throw e;    // terminate the loop without installing the remaining drivers
                }
            }
        }
예제 #2
0
        public virtual void UpdateDrivers()
        {
            string[]      sourceDirs     = Directory.GetDirectories(EucaConstant.EucaDriverSourceDir);
            List <String> updatedDrivers = new List <string>();

            foreach (string dir in sourceDirs)
            {
                string driver = null;
                string dest   = null;
                try
                {
                    driver = dir.Substring(dir.LastIndexOf("\\") + 1);
                    dest   = EucaConstant.EucaDriverDestinationDir + "\\" + driver;

                    if (DriverExists(dir, dest))
                    {
#if EUCA_DEBUG
                        LogTools.Info(string.Format("Drivers in {0} / {1} are the same", dir, dest));
#endif
                        continue;
                    }
                    // rename the old driver for backup
                    string destOld = dest + ".old";
                    if (Directory.Exists(destOld))
                    {
                        Directory.Delete(destOld);
                    }
                    if (Directory.Exists(dest))
                    {
                        Directory.Move(dest, destOld);
                    }

                    Directory.CreateDirectory(dest);
                    foreach (string file in Directory.GetFiles(dir))
                    {
                        string filename = file.Substring(file.LastIndexOf("\\") + 1);
                        File.Copy(file, string.Format("{0}\\{1}", dest, filename));
                    }
                    updatedDrivers.Add(dest);
                }
                catch (Exception e)
                {
                    Program.Log(string.Format("Could not copy driver directory from {0} to {1}", dir, dest));
                    Program.Log(e.StackTrace);
                }
            }

            InstallDrivers(updatedDrivers.ToArray());
        }