Skip to content

Commit 6352ea7

Browse files
committed
Save the package file
1 parent 04d3058 commit 6352ea7

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

LiveWriterPluginManager/Controls/CreatePackageControl.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
Grid.Row="2"
9797
HorizontalAlignment="Right"
9898
Margin="10"
99-
IsEnabled="{Binding IsValidPackage}" />
99+
IsEnabled="{Binding IsValidPackage}"
100+
Command="{Binding CreatePackageCommand}"/>
100101
</Grid>
101102
</UserControl>

LiveWriterPluginManager/Services/ZipService.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace LiveWriterPluginManager.Services
1313
public interface IZipService
1414
{
1515
Task<Plugin> UnzipFileAsync(string filePath);
16-
Task ZipFilesAsync(string[] files, string outputFile);
16+
Task<bool> ZipFilesAsync(string[] files, string outputFile, Manifest manifest);
1717
}
1818

1919
public class ZipService : IZipService
@@ -68,9 +68,38 @@ await Task.Run(async () =>
6868
return result;
6969
}
7070

71-
public Task ZipFilesAsync(string[] files, string outputFile)
71+
public async Task<bool> ZipFilesAsync(string[] files, string outputFile, Manifest manifest)
7272
{
73-
return Task.FromResult(0);
73+
var manifestJson = JsonConvert.SerializeObject(manifest);
74+
var tempManifestFile = $"{Path.GetTempPath()}{Manifest.ManifestFileName}";
75+
if (File.Exists(tempManifestFile))
76+
{
77+
File.Delete(tempManifestFile);
78+
}
79+
80+
File.WriteAllText(tempManifestFile, manifestJson);
81+
82+
var tcs = new TaskCompletionSource<bool>();
83+
await Task.Run(() =>
84+
{
85+
try
86+
{
87+
using (var zipFile = new ZipFile())
88+
{
89+
zipFile.AddFile(tempManifestFile, "");
90+
zipFile.AddFiles(files, false, "");
91+
zipFile.Save(outputFile);
92+
}
93+
94+
tcs.SetResult(true);
95+
}
96+
catch
97+
{
98+
tcs.SetResult(false);
99+
}
100+
});
101+
102+
return await tcs.Task;
74103
}
75104

76105
private static Task<Manifest> ReadManifest(string extractPath)

LiveWriterPluginManager/ViewModel/CreatePackageViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ public RelayCommand CreatePackageCommand
8585
return;
8686
}
8787

88+
var manifest = ManifestViewModel.GetManifest();
8889
var packageFile = _fileService.ChoosePackageLocation();
8990
var filePaths = Files.Select(x => x.Path).ToArray();
9091

91-
await _zipService.ZipFilesAsync(filePaths, packageFile);
92+
await _zipService.ZipFilesAsync(filePaths, packageFile, manifest);
9293
});
9394
}
9495
}

0 commit comments

Comments
 (0)