Install the software on the PDA Program During the process, you need to copy files under a specific directory to the device. Generally, we can embed these files into the cab package. However, in this program, the directory structure is complex, the number of data files is very large, and the customer may add or delete these files as needed when distributing programs to the end user. Therefore, the files must be encoded to dynamically copy files.
The basic idea is to use the rapi provided by ActiveSync. Because the program is written in C #, directly calling the API is difficult and error-prone. Here we use the class library in opennetcf, named opennetcf. desktop. the complete encapsulation of rapi is provided under the namespace of communication.
Follow a fixed process. First, create a cab project. The following is the copy file called by the installer class in the cab. Code Disconnected: Public Class Copyer
{
Private Rapi = New Rapi ();
Private String Root_dir_pda = " \ Program Files \ XXX \\ " ;
Private String Cdir = "" ;
Public Copyer ( String Root)
{
Cdir=Root;
}
Private Void Internalcopydirectory (directoryinfo info)
{
Try
{
String SRC = Info. fullname;
String Dest = Info. fullname. Replace (cdir, root_dir_pda );
If (Rapi. devicefileexists (DEST) = False )
Rapi. createdevicedirectory (DEST );
}
Catch
{
}
}
Private Void Internalcopyfile (fileinfo file)
{
Try
{
String Src2 = File. fullname;
String Dest2 = File. fullname. Replace (cdir, root_dir_pda );
If (Rapi. devicefileexists (dest2) = False )
Rapi. copyfiletodevice (src2, dest2 );
}
Catch
{
}
}
Private Void Internalcopy (directoryinfo info)
{
Internalcopydirectory (Info );
Fileinfo [] files = Info. getfiles ();
Foreach (Fileinfo F In Files)
{
Internalcopyfile (f );
System. Windows. Forms. application. doevents ();
}
}
Public Void Copy (directoryinfo info)
{
Rapi. Connect ( True , 20000 );
Internalcopy (Info );
Directoryinfo [] Infos = Info. getdirectories ( " * " , Searchoption. alldirectories );
Foreach (Directoryinfo I In Infos)
Internalcopy (I );
Rapi. Disconnect ();
}
}
Because the communication speed between PCs and PDAs is relatively slow, a progress bar must be displayed during file copying to improve user experience. I am not familiar with how to call the API in MSI to display the progress bar. Therefore, I use application in internalcopy. doevents activates the timer in the main thread to update a custom form that contains the progress bar to simulate the replication progress, which is a bit confusing to the user.
Now, the rest is to create the MSI project, add some common operations such as cab, of course, there are also required parameter passing code :) This is omitted here.