cronapp-cordova-plugin-contentsync 4.4.0-RC7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +11 -0
- package/README.md +372 -0
- package/package-lock.json +1545 -0
- package/package.json +58 -0
- package/plugin.xml +93 -0
- package/sample/css/index.css +128 -0
- package/sample/img/logo.png +0 -0
- package/sample/index.html +47 -0
- package/sample/js/index.js +152 -0
- package/spec/helper/cordova.js +83 -0
- package/spec/index.spec.js +334 -0
- package/src/android/Sync.java +1102 -0
- package/src/browser/Sync.js +20 -0
- package/src/ios/ContentSync.h +74 -0
- package/src/ios/ContentSync.m +1002 -0
- package/src/ios/SSZipArchive.h +52 -0
- package/src/ios/SSZipArchive.m +540 -0
- package/src/ios/minizip/crypt.h +131 -0
- package/src/ios/minizip/ioapi.c +239 -0
- package/src/ios/minizip/ioapi.h +201 -0
- package/src/ios/minizip/mztools.c +284 -0
- package/src/ios/minizip/mztools.h +31 -0
- package/src/ios/minizip/unzip.c +2153 -0
- package/src/ios/minizip/unzip.h +437 -0
- package/src/ios/minizip/zip.c +2022 -0
- package/src/ios/minizip/zip.h +362 -0
- package/src/windows/SyncProxy.js +279 -0
- package/src/windows/ZipWinProj/PGZipInflate.cs +94 -0
- package/src/windows/ZipWinProj/Properties/AssemblyInfo.cs +30 -0
- package/src/windows/ZipWinProj/ZipWinProj.csproj +57 -0
- package/src/wp8/Sync.cs +746 -0
- package/src/wp8/Unzip.cs +481 -0
- package/tests/anyfile.txt +1 -0
- package/tests/archives/www1.zip +0 -0
- package/tests/archives/www2.zip +0 -0
- package/tests/package.json +11 -0
- package/tests/plugin.xml +22 -0
- package/tests/scripts/start-server.sh +2 -0
- package/tests/scripts/stop-server.sh +1 -0
- package/tests/tests.js +255 -0
- package/www/index.js +285 -0
package/src/wp8/Unzip.cs
ADDED
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using System.Diagnostics;
|
|
4
|
+
using System.IO;
|
|
5
|
+
using System.IO.IsolatedStorage;
|
|
6
|
+
using System.Linq;
|
|
7
|
+
using System.Runtime.Serialization;
|
|
8
|
+
using System.Text;
|
|
9
|
+
using System.Threading.Tasks;
|
|
10
|
+
using System.Windows;
|
|
11
|
+
using System.Windows.Resources;
|
|
12
|
+
|
|
13
|
+
namespace WPCordovaClassLib.Cordova.Commands
|
|
14
|
+
{
|
|
15
|
+
public class UnZip : BaseCommand
|
|
16
|
+
{
|
|
17
|
+
// Sync strategy codes
|
|
18
|
+
public const int Replace = 1;
|
|
19
|
+
public const int Merge = 2;
|
|
20
|
+
|
|
21
|
+
/// <summary>
|
|
22
|
+
/// Represents a singular progress event to be passed back to javascript
|
|
23
|
+
/// </summary>
|
|
24
|
+
[DataContract]
|
|
25
|
+
public class FileUnzipProgress
|
|
26
|
+
{
|
|
27
|
+
/// <summary>
|
|
28
|
+
/// amount loaded
|
|
29
|
+
/// </summary>
|
|
30
|
+
[DataMember(Name = "loaded", IsRequired = true)]
|
|
31
|
+
public long Loaded { get; set; }
|
|
32
|
+
/// <summary>
|
|
33
|
+
/// Total
|
|
34
|
+
/// </summary>
|
|
35
|
+
[DataMember(Name = "total", IsRequired = false)]
|
|
36
|
+
public long Total { get; set; }
|
|
37
|
+
|
|
38
|
+
public FileUnzipProgress(long total = 0, long loaded = 0)
|
|
39
|
+
{
|
|
40
|
+
Loaded = loaded;
|
|
41
|
+
Total = total;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public void unzip(string srcFilePath, string destPath, int type)
|
|
46
|
+
{
|
|
47
|
+
using (IsolatedStorageFile appStorage = IsolatedStorageFile.GetUserStoreForApplication())
|
|
48
|
+
{
|
|
49
|
+
// DEBUG here to copy file from dll to isostore ...
|
|
50
|
+
// this is only really needed if you want to test with a file in your package/project
|
|
51
|
+
StreamResourceInfo fileResourceStreamInfo = Application.GetResourceStream(new Uri(srcFilePath, UriKind.Relative));
|
|
52
|
+
if (fileResourceStreamInfo != null)
|
|
53
|
+
{
|
|
54
|
+
using (BinaryReader br = new BinaryReader(fileResourceStreamInfo.Stream))
|
|
55
|
+
{
|
|
56
|
+
byte[] data = br.ReadBytes((int)fileResourceStreamInfo.Stream.Length);
|
|
57
|
+
// This will truncate/overwrite an existing file, or
|
|
58
|
+
using (IsolatedStorageFileStream outFile = appStorage.OpenFile(srcFilePath, FileMode.Create))
|
|
59
|
+
{
|
|
60
|
+
using (var writer = new BinaryWriter(outFile))
|
|
61
|
+
{
|
|
62
|
+
writer.Write(data);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if(type == Replace)
|
|
69
|
+
{
|
|
70
|
+
DeleteDirectoryRecursively(appStorage, destPath);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
IsolatedStorageFileStream zipStream = null;
|
|
74
|
+
ZipArchive zipArch = null;
|
|
75
|
+
|
|
76
|
+
try
|
|
77
|
+
{
|
|
78
|
+
zipStream = new IsolatedStorageFileStream(srcFilePath, FileMode.Open, FileAccess.Read, appStorage);
|
|
79
|
+
}
|
|
80
|
+
catch (Exception)
|
|
81
|
+
{
|
|
82
|
+
Debug.WriteLine("File not found :: " + srcFilePath);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (zipStream != null)
|
|
87
|
+
{
|
|
88
|
+
zipArch = new ZipArchive(zipStream);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (zipArch != null)
|
|
92
|
+
{
|
|
93
|
+
int totalFiles = zipArch.FileNames.Count();
|
|
94
|
+
int current = 0;
|
|
95
|
+
try
|
|
96
|
+
{
|
|
97
|
+
foreach (string filename in zipArch.FileNames)
|
|
98
|
+
{
|
|
99
|
+
string destFilePath = destPath + "/" + filename;
|
|
100
|
+
|
|
101
|
+
string directoryName = getDirectoryName(destFilePath);
|
|
102
|
+
|
|
103
|
+
//Debug.WriteLine("upacking file : " + filename + " to : " + destFilePath);
|
|
104
|
+
|
|
105
|
+
if (!appStorage.DirectoryExists(directoryName))
|
|
106
|
+
{
|
|
107
|
+
appStorage.CreateDirectory(directoryName);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
using (Stream readStream = zipArch.GetFileStream(filename))
|
|
113
|
+
{
|
|
114
|
+
if (readStream != null)
|
|
115
|
+
{
|
|
116
|
+
using (FileStream outStream = new IsolatedStorageFileStream(destFilePath, FileMode.Create, FileAccess.Write, appStorage))
|
|
117
|
+
{
|
|
118
|
+
WriteStreamToPath(readStream, outStream);
|
|
119
|
+
FileUnzipProgress progEvt = new FileUnzipProgress(totalFiles, current++);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
zipStream.Close();
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
catch (Exception)
|
|
128
|
+
{
|
|
129
|
+
Debug.WriteLine("File not found :: " + srcFilePath);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private void WriteStreamToPath(Stream readStream, Stream outStream)
|
|
136
|
+
{
|
|
137
|
+
|
|
138
|
+
long totalBytes = readStream.Length;
|
|
139
|
+
int bytesRead = 0;
|
|
140
|
+
|
|
141
|
+
using (BinaryReader reader = new BinaryReader(readStream))
|
|
142
|
+
{
|
|
143
|
+
using (BinaryWriter writer = new BinaryWriter(outStream))
|
|
144
|
+
{
|
|
145
|
+
int BUFFER_SIZE = 1024;
|
|
146
|
+
byte[] buffer;
|
|
147
|
+
|
|
148
|
+
while (true)
|
|
149
|
+
{
|
|
150
|
+
buffer = reader.ReadBytes(BUFFER_SIZE);
|
|
151
|
+
bytesRead += buffer.Length;
|
|
152
|
+
if (buffer.Length > 0)
|
|
153
|
+
{
|
|
154
|
+
writer.Write(buffer);
|
|
155
|
+
}
|
|
156
|
+
else
|
|
157
|
+
{
|
|
158
|
+
writer.Close();
|
|
159
|
+
reader.Close();
|
|
160
|
+
outStream.Close();
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Gets the full path without the filename
|
|
170
|
+
private string getDirectoryName(String filePath)
|
|
171
|
+
{
|
|
172
|
+
string directoryName;
|
|
173
|
+
try
|
|
174
|
+
{
|
|
175
|
+
directoryName = filePath.Substring(0, filePath.LastIndexOf('/'));
|
|
176
|
+
}
|
|
177
|
+
catch
|
|
178
|
+
{
|
|
179
|
+
directoryName = "";
|
|
180
|
+
}
|
|
181
|
+
return directoryName;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// helper function from: http://stackoverflow.com/questions/18422331/easy-way-to-recursively-delete-directories-in-isolatedstorage-on-wp7-8
|
|
185
|
+
private void DeleteDirectoryRecursively(IsolatedStorageFile storageFile, String dirName)
|
|
186
|
+
{
|
|
187
|
+
try
|
|
188
|
+
{
|
|
189
|
+
String pattern = dirName + @"\*";
|
|
190
|
+
String[] files = storageFile.GetFileNames(pattern);
|
|
191
|
+
foreach (var fName in files)
|
|
192
|
+
{
|
|
193
|
+
storageFile.DeleteFile(Path.Combine(dirName, fName));
|
|
194
|
+
}
|
|
195
|
+
String[] dirs = storageFile.GetDirectoryNames(pattern);
|
|
196
|
+
foreach (var dName in dirs)
|
|
197
|
+
{
|
|
198
|
+
DeleteDirectoryRecursively(storageFile, Path.Combine(dirName, dName));
|
|
199
|
+
}
|
|
200
|
+
if (storageFile.DirectoryExists(dirName))
|
|
201
|
+
{
|
|
202
|
+
storageFile.DeleteDirectory(dirName);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch(Exception e)
|
|
206
|
+
{
|
|
207
|
+
Debug.WriteLine("Unable to delete directory : " + dirName);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/// <summary>
|
|
212
|
+
/// Class used for storing file entry information when
|
|
213
|
+
/// parsing the central file directory.
|
|
214
|
+
/// </summary>
|
|
215
|
+
private class ZipArchiveEntry
|
|
216
|
+
{
|
|
217
|
+
public string Filename;
|
|
218
|
+
public int FileStart;
|
|
219
|
+
public int CompressedLength;
|
|
220
|
+
public int Length;
|
|
221
|
+
public int CRC32;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
private class ZipArchive : IDisposable
|
|
225
|
+
{
|
|
226
|
+
private const int CENTRAL_FILE_HDR_SIG = 0x02014b50;
|
|
227
|
+
private const int END_CENTRAL_DIR_SIG = 0x06054b50;
|
|
228
|
+
|
|
229
|
+
private Stream ZipStream;
|
|
230
|
+
private List<ZipArchiveEntry> _fileEntries;
|
|
231
|
+
|
|
232
|
+
public ZipArchive(Stream zipFileStream)
|
|
233
|
+
{
|
|
234
|
+
if (!zipFileStream.CanSeek)
|
|
235
|
+
{
|
|
236
|
+
throw new NotSupportedException("zipFileStream must support seeking");
|
|
237
|
+
}
|
|
238
|
+
else
|
|
239
|
+
{
|
|
240
|
+
ZipStream = zipFileStream;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public List<ZipArchiveEntry> FileEntries
|
|
245
|
+
{
|
|
246
|
+
get
|
|
247
|
+
{
|
|
248
|
+
if (_fileEntries == null)
|
|
249
|
+
{
|
|
250
|
+
InflateDirectory();
|
|
251
|
+
}
|
|
252
|
+
return _fileEntries;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
/// <summary>
|
|
258
|
+
/// Gets the file stream for the specified file. Returns null if the file could not be found.
|
|
259
|
+
/// </summary>
|
|
260
|
+
/// <param name="filename">The filename.</param>
|
|
261
|
+
/// <returns>Stream to file inside zip stream</returns>
|
|
262
|
+
public Stream GetFileStream(string filename)
|
|
263
|
+
{
|
|
264
|
+
long position = ZipStream.Position;
|
|
265
|
+
ZipStream.Seek(0, SeekOrigin.Begin);
|
|
266
|
+
Uri fileUri = new Uri(filename, UriKind.Relative);
|
|
267
|
+
StreamResourceInfo info = new StreamResourceInfo(ZipStream, null);
|
|
268
|
+
StreamResourceInfo stream = System.Windows.Application.GetResourceStream(info, fileUri);
|
|
269
|
+
ZipStream.Position = position;
|
|
270
|
+
if (stream != null)
|
|
271
|
+
{
|
|
272
|
+
return stream.Stream;
|
|
273
|
+
}
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/// <summary>
|
|
278
|
+
/// Gets a list of file names embedded in the zip file.
|
|
279
|
+
/// </summary>
|
|
280
|
+
/// <param name="stream">The stream for a zip file.</param>
|
|
281
|
+
/// <returns>List of file names</returns>
|
|
282
|
+
public IEnumerable<string> FileNames
|
|
283
|
+
{
|
|
284
|
+
get
|
|
285
|
+
{
|
|
286
|
+
return (from entry in FileEntries
|
|
287
|
+
where (!entry.Filename.EndsWith("/") &&
|
|
288
|
+
!entry.Filename.StartsWith("__MACOSX/"))
|
|
289
|
+
select entry.Filename);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/// <summary>
|
|
294
|
+
/// Gets a list of directories embedded in the zip file
|
|
295
|
+
/// </summary>
|
|
296
|
+
public IEnumerable<string> DirectoriesName
|
|
297
|
+
{
|
|
298
|
+
get
|
|
299
|
+
{
|
|
300
|
+
return (from entry in FileEntries
|
|
301
|
+
where (entry.Filename.EndsWith("/")
|
|
302
|
+
&& !entry.Filename.StartsWith("__MACOSX/"))
|
|
303
|
+
select entry.Filename);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/***************************************************
|
|
308
|
+
4.3.16 End of central directory record:
|
|
309
|
+
end of central dir signature 4 bytes (0x06054b50)
|
|
310
|
+
number of this disk 2 bytes
|
|
311
|
+
number of the disk with the
|
|
312
|
+
start of the central directory 2 bytes
|
|
313
|
+
total number of entries in the
|
|
314
|
+
central directory on this disk 2 bytes
|
|
315
|
+
total number of entries in
|
|
316
|
+
the central directory 2 bytes
|
|
317
|
+
size of the central directory 4 bytes
|
|
318
|
+
offset of start of central
|
|
319
|
+
directory with respect to
|
|
320
|
+
the starting disk number 4 bytes
|
|
321
|
+
.ZIP file comment length 2 bytes
|
|
322
|
+
.ZIP file comment (variable size)
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
/***************************************************
|
|
326
|
+
File header:
|
|
327
|
+
central file header signature 4 bytes (0x02014b50)
|
|
328
|
+
version made by 2 bytes
|
|
329
|
+
version needed to extract 2 bytes
|
|
330
|
+
general purpose bit flag 2 bytes
|
|
331
|
+
compression method 2 bytes
|
|
332
|
+
last mod file time 2 bytes
|
|
333
|
+
last mod file date 2 bytes
|
|
334
|
+
crc-32 4 bytes
|
|
335
|
+
compressed size 4 bytes
|
|
336
|
+
uncompressed size 4 bytes
|
|
337
|
+
file name length 2 bytes
|
|
338
|
+
extra field length 2 bytes
|
|
339
|
+
file comment length 2 bytes
|
|
340
|
+
disk number start 2 bytes
|
|
341
|
+
internal file attributes 2 bytes
|
|
342
|
+
external file attributes 4 bytes
|
|
343
|
+
relative offset of local header 4 bytes
|
|
344
|
+
file name (variable size)
|
|
345
|
+
extra field (variable size)
|
|
346
|
+
file comment (variable size)
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
private List<ZipArchiveEntry> InflateDirectory()
|
|
351
|
+
{
|
|
352
|
+
_fileEntries = new List<ZipArchiveEntry>();
|
|
353
|
+
|
|
354
|
+
BinaryReader reader = new BinaryReader(ZipStream);
|
|
355
|
+
|
|
356
|
+
reader.BaseStream.Seek(-4, SeekOrigin.End);
|
|
357
|
+
// skip back
|
|
358
|
+
while (reader.ReadInt32() != END_CENTRAL_DIR_SIG)
|
|
359
|
+
{
|
|
360
|
+
reader.BaseStream.Seek(-5, SeekOrigin.Current);
|
|
361
|
+
}
|
|
362
|
+
// skip over number of this disk, number of the disk with dir start, total number of entries on this disk
|
|
363
|
+
reader.BaseStream.Seek(6, SeekOrigin.Current);
|
|
364
|
+
short entryCount = reader.ReadInt16();
|
|
365
|
+
int directorySize = reader.ReadInt32();
|
|
366
|
+
int directoryStart = reader.ReadInt32();
|
|
367
|
+
reader.BaseStream.Seek(directoryStart, SeekOrigin.Begin);
|
|
368
|
+
bool doRebuild = false;
|
|
369
|
+
|
|
370
|
+
for (int i = 0; i < entryCount; i++)
|
|
371
|
+
{
|
|
372
|
+
if (reader.ReadInt32() == CENTRAL_FILE_HDR_SIG)
|
|
373
|
+
{
|
|
374
|
+
ZipArchiveEntry zipEntry = new ZipArchiveEntry();
|
|
375
|
+
|
|
376
|
+
reader.BaseStream.Seek(4, SeekOrigin.Current);
|
|
377
|
+
short flags = reader.ReadInt16(); // read general purpose bit flag
|
|
378
|
+
|
|
379
|
+
if ((flags & 8) > 0) //Silverlight doesn't like this format. We'll "fix it" further below
|
|
380
|
+
{
|
|
381
|
+
doRebuild = true;
|
|
382
|
+
}
|
|
383
|
+
// skip: compression method, last mod file time, last mod file date
|
|
384
|
+
reader.BaseStream.Seek(6, SeekOrigin.Current);
|
|
385
|
+
|
|
386
|
+
zipEntry.CRC32 = reader.ReadInt32();
|
|
387
|
+
zipEntry.CompressedLength = reader.ReadInt32();
|
|
388
|
+
zipEntry.Length = reader.ReadInt32();
|
|
389
|
+
|
|
390
|
+
short fileNameLength = reader.ReadInt16();
|
|
391
|
+
short extraFieldLength = reader.ReadInt16();
|
|
392
|
+
short fileCommentLength = reader.ReadInt16();
|
|
393
|
+
|
|
394
|
+
// skip disk number start, internal file attr, ext file attr
|
|
395
|
+
reader.BaseStream.Seek(8, SeekOrigin.Current);
|
|
396
|
+
|
|
397
|
+
zipEntry.FileStart = reader.ReadInt32();
|
|
398
|
+
zipEntry.Filename = new string(reader.ReadChars(fileNameLength));
|
|
399
|
+
_fileEntries.Add(zipEntry);
|
|
400
|
+
|
|
401
|
+
reader.BaseStream.Seek(extraFieldLength + fileCommentLength, SeekOrigin.Current);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (doRebuild)
|
|
405
|
+
{
|
|
406
|
+
// if file size is reported after the compressed data the filestream is unsupported by silverlight
|
|
407
|
+
MemoryStream newZipStream = new MemoryStream();
|
|
408
|
+
BinaryWriter writer = new BinaryWriter(newZipStream);
|
|
409
|
+
|
|
410
|
+
RebuildEntries(ref reader, ref writer);
|
|
411
|
+
|
|
412
|
+
// rewind
|
|
413
|
+
reader.BaseStream.Seek(directoryStart, SeekOrigin.Begin);
|
|
414
|
+
//Rebuild directory
|
|
415
|
+
RebuildDirectory(ref reader, ref writer);
|
|
416
|
+
|
|
417
|
+
writer.Write(reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)));
|
|
418
|
+
ZipStream = newZipStream; //Swap to use our newly cleaned stream
|
|
419
|
+
}
|
|
420
|
+
return _fileEntries;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private void RebuildDirectory(ref BinaryReader reader, ref BinaryWriter writer)
|
|
424
|
+
{
|
|
425
|
+
for (int i = 0; i < _fileEntries.Count; i++)
|
|
426
|
+
{
|
|
427
|
+
writer.Write(reader.ReadBytes(8));
|
|
428
|
+
byte flag = reader.ReadByte();
|
|
429
|
+
writer.Write((byte)(0xF7 & flag)); //set 3rd hobbit to 0 for new format
|
|
430
|
+
writer.Write(reader.ReadBytes(19));
|
|
431
|
+
short filenamelength = reader.ReadInt16();
|
|
432
|
+
writer.Write(filenamelength);
|
|
433
|
+
short extrafieldlength = reader.ReadInt16();
|
|
434
|
+
writer.Write(extrafieldlength);
|
|
435
|
+
short filecommentlength = reader.ReadInt16();
|
|
436
|
+
writer.Write(filecommentlength);
|
|
437
|
+
writer.Write(reader.ReadBytes(8));
|
|
438
|
+
writer.Write(_fileEntries[i].FileStart);
|
|
439
|
+
reader.BaseStream.Seek(4, SeekOrigin.Current);
|
|
440
|
+
writer.Write(reader.ReadBytes(filenamelength + extrafieldlength + filecommentlength));
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private void RebuildEntries(ref BinaryReader reader, ref BinaryWriter writer)
|
|
445
|
+
{
|
|
446
|
+
//Rebuild file entries
|
|
447
|
+
foreach (ZipArchiveEntry entry in _fileEntries)
|
|
448
|
+
{
|
|
449
|
+
ZipArchiveEntry e = entry;
|
|
450
|
+
reader.BaseStream.Seek(entry.FileStart, SeekOrigin.Begin);
|
|
451
|
+
e.FileStart = (int)writer.BaseStream.Position;
|
|
452
|
+
writer.Write(reader.ReadBytes(6));
|
|
453
|
+
|
|
454
|
+
short flag = reader.ReadInt16();
|
|
455
|
+
writer.Write((short)(0xF7 & flag)); //set 3rd hobbit to 0 for new format
|
|
456
|
+
writer.Write(reader.ReadBytes(6));
|
|
457
|
+
writer.Write(entry.CRC32);
|
|
458
|
+
writer.Write(entry.CompressedLength);
|
|
459
|
+
writer.Write(entry.Length);
|
|
460
|
+
writer.Write((short)entry.Filename.Length);
|
|
461
|
+
reader.BaseStream.Seek(14, SeekOrigin.Current);
|
|
462
|
+
short fieldLength = reader.ReadInt16();
|
|
463
|
+
writer.Write(fieldLength);
|
|
464
|
+
writer.Write(reader.ReadBytes(entry.Filename.Length + fieldLength + entry.CompressedLength));
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
#region IDisposable Members
|
|
469
|
+
|
|
470
|
+
public void Dispose()
|
|
471
|
+
{
|
|
472
|
+
if (ZipStream != null)
|
|
473
|
+
{
|
|
474
|
+
ZipStream.Dispose();
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
#endregion
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Test file that is enumerated before the directories.
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "cronapp-cordova-plugin-contentsync-tests",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Tests for CronApp/cronapp-cordova-plugin-contentsync",
|
|
5
|
+
"main": "tests.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "Apache-2.0"
|
|
11
|
+
}
|
package/tests/plugin.xml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
|
+
xmlns:rim="http://www.blackberry.com/ns/widgets"
|
|
4
|
+
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
5
|
+
id="cronapp-cordova-plugin-contentsync-tests"
|
|
6
|
+
version="1.0.0">
|
|
7
|
+
<name>Cronapp Content Sync Plugin Tests</name>
|
|
8
|
+
<license>Apache 2.0</license>
|
|
9
|
+
|
|
10
|
+
<dependency id="cordova-plugin-file" version=">=4.0.0" />
|
|
11
|
+
|
|
12
|
+
<!-- ensure proper file plugin setting -->
|
|
13
|
+
<config-file target="config.xml" parent="/*">
|
|
14
|
+
<preference name="iosPersistentFileLocation" value="Library" />
|
|
15
|
+
</config-file>
|
|
16
|
+
|
|
17
|
+
<js-module src="tests.js" name="tests">
|
|
18
|
+
</js-module>
|
|
19
|
+
|
|
20
|
+
<!-- add test file that is enumerated before the directories (see issue #84) -->
|
|
21
|
+
<asset src="anyfile.txt" target="anyfile.txt" />
|
|
22
|
+
</plugin>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ps aux | grep -e "python -m SimpleHTTPServer" | grep -v grep | awk '{print "kill -1 " $2}' | sh
|