Use rapi to dynamically copy files to devices in the PDA installation package

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.