public static extern ReturnCode DsmWin32( [In, Out] TW_IDENTITY origin, [In, Out] TW_IDENTITY destination, DataGroups dg, DataArgumentType dat, Message msg, ref TW_FILESYSTEM data);
ReturnCode DoIt(Message msg, ref TW_FILESYSTEM fileSystem) { if (Is32Bit) { if (IsWin) { return(NativeMethods.DsmWin32(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem)); } if (IsLinux) { return(NativeMethods.DsmLinux32(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem)); } if (IsMac) { return(NativeMethods.DsmMac32(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem)); } } if (IsWin) { return(NativeMethods.DsmWin64(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem)); } if (IsLinux) { return(NativeMethods.DsmLinux64(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem)); } if (IsMac) { return(NativeMethods.DsmMac64(Session.Config.App32, Session.CurrentSource.Identity32, DataGroups.Control, DataArgumentType.FileSystem, msg, ref fileSystem)); } return(ReturnCode.Failure); }
/// <summary> /// This operation copies a file or directory. Absolute and relative pathnames are supported. A file /// may not be overwritten with this command. If an Application wishes to do this, it must first /// delete the unwanted file and then reissue the Copy command. /// The Application specifies the path and name of the entry to be copied in InputName. The /// Application specifies the new patch and name in OutputName. /// It is not permitted to copy files into the root directory. /// </summary> /// <param name="fileSystem">The file system.</param> /// <returns></returns> public ReturnCode Copy(ref TW_FILESYSTEM fileSystem) { return(DoIt(Message.Copy, ref fileSystem)); }
/// <summary> /// This operation selects the current device within the Source (camera, storage, etc). If the device is /// a <see cref="FileType.Domain"/>, then this command enters a directory that can contain <see cref="FileType.Host"/> files. If the /// device is a <see cref="FileType.Host"/>, then this command enters a directory that can contain /// <see cref="FileType.Directory"/> files. If the device is a <see cref="FileType.Directory"/>, then this command enters a /// directory that can contain <see cref="FileType.Directory"/> or <see cref="FileType.Image"/> files. /// </summary> /// <param name="fileSystem">The file system.</param> /// <returns></returns> public ReturnCode ChangeDirectory(ref TW_FILESYSTEM fileSystem) { return(DoIt(Message.ChangeDirectory, ref fileSystem)); }
/// <summary> /// This operation selects the destination directory within the Source (camera, storage, etc), where /// images captured using CapAutomaticCapture will be stored. This command only selects /// the destination directory (a file of type Directory). The directory must exist and be /// accessible to the Source. The creation of images within the directory is at the discretion of the /// Source, and may result in the creation of additional sub-directories. /// </summary> /// <param name="fileSystem">The file system.</param> /// <returns></returns> public ReturnCode AutomaticCaptureDirectory(ref TW_FILESYSTEM fileSystem) { return(DoIt(Message.AutomaticCaptureDirectory, ref fileSystem)); }
/// <summary> /// This operation renames (and optionally moves) a file or directory. Absolute and relative path /// names are supported. A file may not be overwritten with this command. If an Application /// wishes to do this it must first delete the unwanted file, then issue the rename command. /// The Application specifies the path and name of the entry to be renamed in InputName. The /// Application specifies the new path and name in OutputName. /// Filenames in the root directory cannot be moved or renamed. /// </summary> /// <param name="fileSystem">The file system.</param> /// <returns></returns> public ReturnCode Rename(ref TW_FILESYSTEM fileSystem) { return(DoIt(Message.Rename, ref fileSystem)); }
/// <summary> /// This operation gets the next filename in a directory, and returns information about that file (the /// same information that can be retrieved with GetInfo). /// </summary> /// <param name="fileSystem">The file system.</param> /// <returns></returns> public ReturnCode GetNextFile(ref TW_FILESYSTEM fileSystem) { return(DoIt(Message.GetNextFile, ref fileSystem)); }
/// <summary> /// This operation fills the information fields in fileSystem. /// InputName contains the absolute or relative path and filename of the requested file. /// OutputName returns the absolute path to the file. /// </summary> /// <param name="fileSystem">The file system.</param> /// <returns></returns> public ReturnCode GetInfo(ref TW_FILESYSTEM fileSystem) { return(DoIt(Message.GetInfo, ref fileSystem)); }
/// <summary> /// This operation formats the specified storage. This operation destroys all images and subdirectories /// under the selected device. Use with caution. /// </summary> /// <param name="fileSystem">The file system.</param> /// <returns></returns> public ReturnCode FormatMedia(ref TW_FILESYSTEM fileSystem) { return(DoIt(Message.FormatMedia, ref fileSystem)); }
/// <summary> /// Get/Set the filesystem... /// </summary> /// <param name="a_dg">Data group</param> /// <param name="a_msg">Operation</param> /// <param name="a_twfilesystem">FILESYSTEM structure</param> /// <returns>TWAIN status</returns> public STS DatFilesystem(DG a_dg, MSG a_msg, ref TW_FILESYSTEM a_twfilesystem) { STS sts; // Submit the work to the TWAIN thread... if ((m_threadTwain != null) && (m_threadTwain.ManagedThreadId != Thread.CurrentThread.ManagedThreadId)) { lock (m_lockTwain) { // Set our command variables... ThreadData threaddata = default(ThreadData); threaddata.twfilesystem = a_twfilesystem; threaddata.dg = a_dg; threaddata.msg = a_msg; threaddata.dat = DAT.FILESYSTEM; long lIndex = m_twaincommand.Submit(threaddata); // Submit the command and wait for the reply... CallerToThreadSet(); ThreadToCallerWaitOne(); // Return the result... a_twfilesystem = m_twaincommand.Get(lIndex).twfilesystem; sts = m_twaincommand.Get(lIndex).sts; // Clear the command variables... m_twaincommand.Delete(lIndex); } return (sts); } // Log it... if (Log.GetLevel() > 0) { Log.LogSendBefore(a_dg.ToString(), DAT.FILESYSTEM.ToString(), a_msg.ToString(), FilesystemToCsv(a_twfilesystem)); } // Windows... if (ms_platform == Platform.WINDOWS) { // Issue the command... try { if (m_blUseLegacyDSM) { sts = (STS)WindowsTwain32DsmEntryFilesystem(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.FILESYSTEM, a_msg, ref a_twfilesystem); } else { sts = (STS)WindowsTwaindsmDsmEntryFilesystem(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.FILESYSTEM, a_msg, ref a_twfilesystem); } } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } } // Linux... else if (ms_platform == Platform.LINUX) { // Issue the command... try { if (GetMachineWordBitSize() == 32) { sts = (STS)LinuxDsmEntryFilesystem(ref m_twidentitylegacyApp, ref m_twidentitylegacyDs, a_dg, DAT.FILESYSTEM, a_msg, ref a_twfilesystem); } else { sts = (STS)Linux64DsmEntryFilesystem(ref m_twidentityApp, ref m_twidentityDs, a_dg, DAT.FILESYSTEM, a_msg, ref a_twfilesystem); } } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } } // Mac OS X, which has to be different... else if (ms_platform == Platform.MACOSX) { // Issue the command... try { sts = (STS)MacosxDsmEntryFilesystem(ref m_twidentitymacosxApp, ref m_twidentitymacosxDs, a_dg, DAT.FILESYSTEM, a_msg, ref a_twfilesystem); } catch { // The driver crashed... Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } } // Uh-oh... else { Log.LogSendAfter(STS.BUMMER.ToString(), ""); return (STS.BUMMER); } // Log it... if (Log.GetLevel() > 0) { Log.LogSendAfter(sts.ToString(), FilesystemToCsv(a_twfilesystem)); } // All done... return (AutoDatStatus(sts)); }
/// <summary> /// This operation deletes a file or directory on the device. Pathnames are not allowed, only the /// name of the file or directory to be deleted can be specified. Recursive deletion can be specified /// by setting the Recursive to TRUE. /// </summary> /// <param name="fileSystem">The file system.</param> /// <returns></returns> public ReturnCode Delete(ref TW_FILESYSTEM fileSystem) { return(DoIt(Message.Delete, ref fileSystem)); }
/// <summary> /// Convert the contents of a string to a filesystem structure... /// </summary> /// <param name="a_twfilesystem">A TWAIN structure</param> /// <param name="a_szFilesystem">A CSV string of the TWAIN structure</param> /// <returns>True if the conversion is successful</returns> public bool CsvToFilesystem(ref TW_FILESYSTEM a_twfilesystem, string a_szFilesystem) { // Init stuff... a_twfilesystem = default(TW_FILESYSTEM); // Build the string... try { string[] asz = CSV.Parse(a_szFilesystem); // Grab the values... a_twfilesystem.InputName.Set(asz[0]); a_twfilesystem.OutputName.Set(asz[1]); a_twfilesystem.Context = (IntPtr)UInt64.Parse(asz[2]); a_twfilesystem.Recursive = int.Parse(asz[3]); a_twfilesystem.FileType = int.Parse(asz[4]); a_twfilesystem.Size = uint.Parse(asz[5]); a_twfilesystem.CreateTimeDate.Set(asz[6]); a_twfilesystem.ModifiedTimeDate.Set(asz[7]); a_twfilesystem.FreeSpace = (uint)UInt64.Parse(asz[8]); a_twfilesystem.NewImageSize = (uint)UInt64.Parse(asz[9]); a_twfilesystem.NumberOfFiles = (uint)UInt64.Parse(asz[10]); a_twfilesystem.NumberOfSnippets = (uint)UInt64.Parse(asz[11]); a_twfilesystem.DeviceGroupMask = (uint)UInt64.Parse(asz[12]); } catch { return (false); } // All done... return (true); }
/// <summary> /// Convert the contents of a filesystem string to a string that we can show in /// our simple GUI... /// </summary> /// <param name="a_twfilesystem">A TWAIN structure</param> /// <returns>A CSV string of the TWAIN structure</returns> public string FilesystemToCsv(TW_FILESYSTEM a_twfilesystem) { try { CSV csv = new CSV(); csv.Add(a_twfilesystem.InputName.Get()); csv.Add(a_twfilesystem.OutputName.Get()); csv.Add(a_twfilesystem.Context.ToString()); csv.Add(a_twfilesystem.Recursive.ToString()); csv.Add(a_twfilesystem.FileType.ToString()); csv.Add(a_twfilesystem.Size.ToString()); csv.Add(a_twfilesystem.CreateTimeDate.Get()); csv.Add(a_twfilesystem.ModifiedTimeDate.Get()); csv.Add(a_twfilesystem.FreeSpace.ToString()); csv.Add(a_twfilesystem.NewImageSize.ToString()); csv.Add(a_twfilesystem.NumberOfFiles.ToString()); csv.Add(a_twfilesystem.NumberOfSnippets.ToString()); csv.Add(a_twfilesystem.DeviceGroupMask.ToString()); return (csv.Get()); } catch { return ("***error***"); } }
private static extern UInt16 MacosxDsmEntryFilesystem ( ref TW_IDENTITY_MACOSX origin, ref TW_IDENTITY_MACOSX dest, DG dg, DAT dat, MSG msg, ref TW_FILESYSTEM twfilesystem );
private static extern UInt16 Linux64DsmEntryFilesystem ( ref TW_IDENTITY origin, ref TW_IDENTITY dest, DG dg, DAT dat, MSG msg, ref TW_FILESYSTEM twfilesystem );
private static extern UInt16 WindowsTwaindsmDsmEntryFilesystem ( ref TW_IDENTITY_LEGACY origin, ref TW_IDENTITY_LEGACY dest, DG dg, DAT dat, MSG msg, ref TW_FILESYSTEM twfilesystem );