Bonjour,
Et comment ça se passe pour les types propriétaires et les propriétés ?
Par exemple, je veux intégrer fastzip (ICSharpCode.SharpZipLib.dll).
J'utilise, pour décompresser, 2 fonctions que j'ai importées.
Mais il y a un autre élément (ZipEntry) qui est juste un conteneur et qui possède des propriétés.
Bref, ce code ne fonctionne pas sans la DLL, comment faire ?
Lorsque je l’exécute en autarcie, il plante, je pense que ça vient des theEntry.IsFile et autres.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Checksums; using System.Runtime.InteropServices; // Pour inclure les DLL (P/Invoke) namespace ExtraireZip { class Program { [DllImport("ICSharpCode.SharpZipLib")] static extern int Read( byte[] buffer, int offest, int count ); [DllImport("ICSharpCode.SharpZipLib")] static extern ZipEntry GetNextEntry(); static void Main(string[] args) { string msgErr = ""; string pathModule = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); pathModule = (pathModule[pathModule.Length-1] != Path.DirectorySeparatorChar) ? pathModule + Path.DirectorySeparatorChar : pathModule; if ((args.Length > 0)) { if (File.Exists(args[0])) { decompresserRep(args[0], pathModule); } } } static string decompresserRep(string InputPathOfZipFile, string repDestination) { string msgErr = ""; try { if (File.Exists(InputPathOfZipFile)) { repDestination = (repDestination.EndsWith("\\")) ? repDestination.Remove(repDestination.Length - 1, 1) : repDestination; // Enlever l'antiSlash final using (ZipInputStream ZipStream = new ZipInputStream(File.OpenRead(InputPathOfZipFile))) { ZipEntry theEntry; while ((theEntry = ZipStream.GetNextEntry()) != null) { if (theEntry.IsFile) { if (theEntry.Name != "") { string strNewFile = @"" + repDestination + @"\" + theEntry.Name; if (File.Exists(strNewFile)) { continue; } if (!Directory.Exists(Path.GetDirectoryName(strNewFile))) { Directory.CreateDirectory(Path.GetDirectoryName(strNewFile)); } using (FileStream streamWriter = File.Create(strNewFile)) { int size = 2048; byte[] data = new byte[2048]; while (true) { size = ZipStream.Read(data, 0, data.Length); if (size > 0) streamWriter.Write(data, 0, size); else break; } streamWriter.Close(); } } } else if (theEntry.IsDirectory) { string strNewDirectory = @"" + repDestination + @"\" + theEntry.Name; if (!Directory.Exists(strNewDirectory)) { Directory.CreateDirectory(strNewDirectory); } } } ZipStream.Close(); } } } catch (Exception ex) { msgErr = ex.Message; // +" (" + ex.StackTrace + ")."; } return msgErr; } } }
Pouvez vous m'aider ?
Merci d'avance.
David.
Partager