コード例 #1
1
        /// <summary>
        /// Creates a new instance of <see cref="IDriver"/> with the specified arguments,
        /// and loads it according to the specified <see cref="DriverLoad"/> method.
        /// </summary>
        /// <param name="ServiceName">The service name.</param>
        /// <param name="DosName">The dos name.</param>
        /// <param name="File">The system file.</param>
        /// <param name="DriverLoad">The driver load method.</param>
        public static Driver New(string ServiceName, string DosName, FileInfo File, DriverLoad DriverLoad = DriverLoad.Normal)
        {
            if (!Driver.Exists(ServiceName, DosName))
            {
                if (File.Exists == false)
                {
                    throw new FileNotFoundException("The Driver or system file does not exist.");
                }
            }

            var DriverObject = new Driver(ServiceName, DosName, File, DriverLoad);

            try
            {
                DriverObject.Load();
            }
            catch (Exception)
            {
                // ..
            }

            return(DriverObject);
        }
コード例 #2
0
        /// <summary>
        /// Loads the specified driver/system file.
        /// </summary>
        public bool Load()
        {
            if (!this.Loader.CreateDriver(this))
            {
                Log.Error(typeof(Driver), "Failed to create the driver at Load().");
                return(false);
            }

            if (!Driver.Exists(this.ServiceName, this.SymbolicLink))
            {
                Log.Info(typeof(Driver), "Driver doesnt exist yet, loading it now at Load().");

                if (this.Loader.LoadDriver())
                {
                    Log.Info(typeof(Driver), "Driver has been successfully mapped and loaded.");
                }
                else
                {
                    Log.Error(typeof(Driver), "Failed to load the driver at Load().");
                    return(false);
                }
            }
            else
            {
                Log.Warning(typeof(Driver), "Warning, driver already exist at Load().");
            }

            if (this.Handle != null && (!this.Handle.IsInvalid || !this.Handle.IsClosed))
            {
                Log.Warning(typeof(Driver), "Warning, driver already connected at Load().");

                this.Handle.Close();
                this.Handle = null;
            }

            this.Handle = Native.CreateFile(this.SymbolicLink, FileAccess.ReadWrite, FileShare.ReadWrite, IntPtr.Zero, FileMode.Open, 0, IntPtr.Zero);

            if (this.Handle == null || this.Handle.IsInvalid || this.Handle.IsClosed)
            {
                Log.Error(typeof(Driver), "Unable to allocate a mapped file for the driver, aborting.");

                if (!this.Loader.StopDriver())
                {
                    Log.Error(typeof(Driver), "Failed to stop the driver at Load().");
                }

                return(false);
            }

            if (this.Loaded != null)
            {
                try
                {
                    this.Loaded.Invoke(this, EventArgs.Empty);
                }
                catch (Exception)
                {
                    // ..
                }
            }

            return(true);
        }