-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeviceCE.cs
95 lines (81 loc) · 2.79 KB
/
DeviceCE.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using OpenNETCF.Desktop.Communication;
namespace BusCE
{
class DeviceCE
{
public string localPath { get; set; }
public string remotePath { get; set; }
public string remoteFileSearch { get; set; }
private RAPI myRAPI;
public DeviceCE() {
this.localPath = @"c:\";
this.remotePath = @"\";
this.remoteFileSearch = "*.DDD";
}
public DeviceCE(string localPath, string remotePath, string removeFileSearch)
{
this.localPath = localPath;
this.remotePath = remotePath;
this.remoteFileSearch = removeFileSearch;
}
public int getFiles(string localPath, string remotePath, string remoteFileSearch)
{
this.localPath = localPath;
this.remotePath = remotePath;
this.remoteFileSearch = remoteFileSearch;
return getFiles();
}
public int getFiles()
{
this.myRAPI = new RAPI();
try
{
// Controllo se esiste la cartella di destinazione locale
if (!Directory.Exists(localPath))
Directory.CreateDirectory(localPath);
// Creo l'oggetto di cotrollo remoto
if (myRAPI.DevicePresent)
{
myRAPI.Connect();
var fileNames = myRAPI.EnumerateFiles(Path.Combine(remotePath, remoteFileSearch));
// Conta i file trovati
int numFiles = 0;
foreach (var item in fileNames)
numFiles++;
if (numFiles == 0)
return 0;
foreach (FileInformation file in fileNames)
{
/*
if (file.FileAttributes == Convert.ToInt16((int) RAPI.RAPIFileAttributes.Normal));
{
* */
myRAPI.CopyFileFromDevice(
Path.Combine(localPath, file.FileName), // desktop path
Path.Combine(remotePath, file.FileName), // device path
true // overwrite existing file
);
/*}*/
myRAPI.DeleteDeviceFile(file.FileName);
}
}
}
catch
{
return 0;
}
return 0;
}
public bool isConnected()
{
bool result = false;
if (myRAPI != null)
result = myRAPI.DevicePresent;
return result;
}
}
}