/// <summary> /// Copies an existing file to a new file. Overwriting a file of the same name is allowed. /// </summary> /// <param name="device">The device.</param> /// <param name="sourceFileName">The file to copy.</param> /// <param name="destFileName">The name of the destination file. This cannot be a directory.</param> /// <param name="overwrite"><c>true</c> if the destination file can be overwritten; otherwise <c>false</c>.</param> public static void Copy(RemoteDevice device, string sourceFileName, string destFileName, bool overwrite) { if (0 == device.ISession.CeCopyFile(sourceFileName, destFileName, overwrite ? 0 : 1)) { device.ThrowRAPIException(); } }
private static string[] GetFiles(RemoteDevice device, string path, string searchPattern, int flags, bool exclDirs) { if (exclDirs) { flags |= 0x01; // FAF_ATTRIBUTES } int foundCount = 0; if (0 == device.ISession.CeFindAllFiles(Path.Combine(path, searchPattern), flags, ref foundCount, out IntPtr findDataArray)) { device.ThrowRAPIException(); } var list = new List <string>(foundCount); try { CE_FIND_DATA[] fds = new CE_FIND_DATA[foundCount]; IntPtr current = findDataArray; for (int i = 0; i < foundCount; current = (IntPtr)((long)current + Marshal.SizeOf(fds[i++]))) { fds[i] = (CE_FIND_DATA)Marshal.PtrToStructure(current, typeof(CE_FIND_DATA)); if (exclDirs && (0x10 & fds[i].dwFileAttributes) == 0x10 /*FILE_ATTRIBUTE_DIRECTORY*/) { continue; } list.Add(fds[i].Name); } } finally { device.ISession.CeRapiFreeBuffer(findDataArray); } return(list.ToArray()); }
/// <summary> /// Sets the specified <see cref="FileAttributes"/> of a file or directory on a remote device. /// </summary> /// <param name="device">The device.</param> /// <param name="fileName">The path to the file.</param> /// <param name="attr">The desired <see cref="FileAttributes"/>, such as <c>Hidden</c>, <c>ReadOnly</c>, <c>Normal</c>, and <c>Archive</c>.</param> public static void SetAttributes(RemoteDevice device, string fileName, FileAttributes attr) { if (0 == device.ISession.CeSetFileAttributes(fileName, (uint)attr)) { device.ThrowRAPIException(); } }
/// <summary> /// Moves a specified file to a new location, providing the option to specify a new file name. /// </summary> /// <param name="device">The device.</param> /// <param name="sourceFileName">The name of the file to move.</param> /// <param name="destFileName">The new path for the file.</param> public static void Move(RemoteDevice device, string sourceFileName, string destFileName) { if (0 == device.ISession.CeMoveFile(sourceFileName, destFileName)) { device.ThrowRAPIException(); } }
//public static StreamWriter CreateText(RemoteDevice device, string path); /// <summary> /// Deletes the specified file. An exception is not thrown if the specified file does not exist. /// </summary> /// <param name="device">The device.</param> /// <param name="path">The name of the file to be deleted.</param> public static void Delete(RemoteDevice device, string path) { if (0 == device.ISession.CeDeleteFile(path)) { device.ThrowRAPIException(); } }
/// <summary> /// Gets the <see cref="FileAttributes"/> of the file on the path. /// </summary> /// <param name="device">The device.</param> /// <param name="path">The path to the file.</param> /// <returns>The <see cref="FileAttributes"/> of the file on the path.</returns> public static FileAttributes GetAttribtues(RemoteDevice device, string path) { uint ret = device.ISession.CeGetFileAttributes(path); if (ret == 0xFFFFFFFF) { device.ThrowRAPIException(); } return((FileAttributes)ret); }
/// <summary> /// Initializes a new instance of the <see cref="RemoteDatabase"/> class and opens an existing database in the object store on a remote Microsoft® Windows® CE–based device. /// </summary> /// <param name="device">The device.</param> /// <param name="objId">The object identifier of the database to be opened.</param> /// <param name="autoIncr">If set to <c>true</c> current seek position is automatically incremented with each call to the ReadRecordProps method.</param> /// <param name="sortId">Property identifier of the primary key for the sort order in which the database is to be traversed. Subsequent calls to Seek assume this sort order. This parameter can be zero if the sort order is not important.</param> public RemoteDatabase(RemoteDevice device, uint objId, bool autoIncr, uint sortId) { sess = device.ISession; handle = new RemoteDevice.DeviceHandle(sess, sess.CeOpenDatabase(ref objId, null, sortId, autoIncr ? CEDB_AUTOINCREMENT : 0, IntPtr.Zero)); if (handle.IsInvalid) { device.ThrowRAPIException(); } ObjectId = objId; CurrentRecordId = 0; }
/// <summary> /// Creates all directories and subdirectories as specified by path. /// </summary> /// <param name="device">The device.</param> /// <param name="path">The directory path to create.</param> /// <returns>A <see cref="RemoteDirectoryInfo"/> as specified by <paramref name="path"/>.</returns> public static RemoteDirectoryInfo CreateDirectory(RemoteDevice device, string path) { if (path.Length > (MAX_PATH - 1)) { throw new ArgumentException(string.Format("Directory paths may not exceed {0} characters.", MAX_PATH - 1), "pathName"); } if (0 == device.ISession.CeCreateDirectory(path, IntPtr.Zero)) { device.ThrowRAPIException(); } return(new RemoteDirectoryInfo(device, path)); }
/// <summary> /// Deletes an empty directory from a specified path. /// </summary> /// <param name="device">The device.</param> /// <param name="path">The name of the empty directory to remove. This directory must be writable or empty.</param> /// <param name="recursive"><c>true</c> to remove directories, subdirectories, and files in path; otherwise, <c>false</c>.</param> public static void Delete(RemoteDevice device, string path, bool recursive) { if (Exists(device, path)) { if (recursive) { foreach (var file in GetFiles(device, path)) { RemoteFile.Delete(device, file); } foreach (var dir in GetDirectories(device, path)) { Delete(device, dir, true); } } if (0 == device.ISession.CeRemoveDirectory(path)) { device.ThrowRAPIException(); } } }