@@ -13,6 +13,7 @@ namespace LiveWriterPluginManager.Services
1313 public interface IZipService
1414 {
1515 Task < Plugin > UnzipFileAsync ( string filePath ) ;
16+ Task < Tuple < Manifest , string [ ] > > OpenPackageForEditing ( string filePath ) ;
1617 Task < bool > ZipFilesAsync ( string [ ] files , string outputFile , Manifest manifest ) ;
1718 }
1819
@@ -38,24 +39,18 @@ public async Task<Plugin> UnzipFileAsync(string filePath)
3839 var tcs = new TaskCompletionSource < bool > ( ) ;
3940 await Task . Run ( async ( ) =>
4041 {
41- using ( var zipFile = ZipFile . Read ( filePath ) )
42- {
43- zipFile . FlattenFoldersOnExtract = true ;
44- var fileName = Path . GetFileNameWithoutExtension ( filePath ) ;
45-
46- var extractPath = Path . Combine ( AppHelper . PluginsFolder , fileName ) ;
47- zipFile . ExtractAll ( extractPath , ExtractExistingFileAction . OverwriteSilently ) ;
42+ var fileName = Path . GetFileNameWithoutExtension ( filePath ) ;
43+ var extractPath = Path . Combine ( AppHelper . PluginsFolder , fileName ) ;
4844
49- var manifest = await ReadManifest ( extractPath ) ;
45+ var manifest = await ExtractAndReturnManifest ( extractPath , fileName ) ;
5046
51- result = new Plugin
52- {
53- Name = manifest ? . Name ,
54- Path = manifest ? . PluginPath
55- } ;
47+ result = new Plugin
48+ {
49+ Name = manifest ? . Name ,
50+ Path = manifest ? . PluginPath
51+ } ;
5652
57- tcs . SetResult ( true ) ;
58- }
53+ tcs . SetResult ( true ) ;
5954 } ) ;
6055
6156 await tcs . Task ;
@@ -68,6 +63,43 @@ await Task.Run(async () =>
6863 return result ;
6964 }
7065
66+ public async Task < Tuple < Manifest , string [ ] > > OpenPackageForEditing ( string filePath )
67+ {
68+ if ( string . IsNullOrEmpty ( filePath ) )
69+ {
70+ return new Tuple < Manifest , string [ ] > ( new Manifest ( ) , new string [ 0 ] ) ;
71+ }
72+
73+ var tcs = new TaskCompletionSource < Tuple < Manifest , string [ ] > > ( ) ;
74+ await Task . Run ( async ( ) =>
75+ {
76+ var filename = Path . GetFileNameWithoutExtension ( filePath ) ;
77+ var extractPath = Path . Combine ( Path . GetTempPath ( ) , filename ) ;
78+
79+ var manifest = await ExtractAndReturnManifest ( filePath , extractPath ) ;
80+
81+ var directory = new DirectoryInfo ( extractPath ) ;
82+ var files = directory . EnumerateFiles ( ) . Select ( x => x . FullName ) . ToArray ( ) ;
83+
84+ tcs . SetResult ( new Tuple < Manifest , string [ ] > ( manifest , files ) ) ;
85+ } ) ;
86+
87+ var result = await tcs . Task ;
88+ return result ;
89+ }
90+
91+ private static async Task < Manifest > ExtractAndReturnManifest ( string filePath , string extractPath )
92+ {
93+ using ( var zipFile = ZipFile . Read ( filePath ) )
94+ {
95+ zipFile . FlattenFoldersOnExtract = true ;
96+ zipFile . ExtractAll ( extractPath , ExtractExistingFileAction . OverwriteSilently ) ;
97+ }
98+
99+ var manifest = await ReadManifest ( extractPath ) ;
100+ return manifest ;
101+ }
102+
71103 public async Task < bool > ZipFilesAsync ( string [ ] files , string outputFile , Manifest manifest )
72104 {
73105 var manifestJson = JsonConvert . SerializeObject ( manifest ) ;
0 commit comments