Skip to content

Commit b345f57

Browse files
author
兰小方
committed
修改ZipOleObjectFile返回值类型,修复创建空文件夹Bug。
1 parent 3abd459 commit b345f57

1 file changed

Lines changed: 5 additions & 19 deletions

File tree

src/dotnetCampus.OfficeDocumentZipper/MainWindow.xaml.cs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,11 @@ private void Zip_OnClick(object sender, RoutedEventArgs e)
246246

247247
var directory = OfficeFolder.Text;
248248

249-
DirectoryInfo[] directoryInfos = null;
250-
251249
// 涉及IO操作,最好捕获一下异常。
252250
try
253251
{
254-
// 这个步骤是查找问价夹里是否存在oleObj元素映射的xlsx文件,并进行压缩处理。
255-
directoryInfos = ZipOleObjectFile();
252+
// 这个步骤是查找文件夹里是否存在oleObj元素映射的xlsx文件,并进行压缩处理。
253+
ZipOleObjectFile();
256254
}
257255
catch (Exception exception)
258256
{
@@ -264,14 +262,8 @@ private void Zip_OnClick(object sender, RoutedEventArgs e)
264262
// 涉及IO操作,最好捕获一下异常。
265263
try
266264
{
267-
if (directoryInfos is not null)
268-
{
269-
foreach (var directoryInfo in directoryInfos)
270-
{
271-
// 进行恢复现场。
272-
directoryInfo.Create();
273-
}
274-
}
265+
// 还原ZipOleObjectFile方法删除的Excel文件解压出来的问价夹。
266+
UnZipOleObjectFile();
275267
}
276268
catch (Exception exception)
277269
{
@@ -292,7 +284,7 @@ private void Zip_OnClick(object sender, RoutedEventArgs e)
292284
/// </summary>
293285
/// <returns>返回删除的文件夹的集合。</returns>
294286

295-
private DirectoryInfo[] ZipOleObjectFile()
287+
private void ZipOleObjectFile()
296288
{
297289
// 获取OleObj的映射的xlsx文件。
298290
var oleObjDirectory = Path.Combine(OfficeFolder.Text, "ppt\\embeddings\\");
@@ -316,13 +308,7 @@ private DirectoryInfo[] ZipOleObjectFile()
316308
deleteDirectories.Add(directoryInfo);
317309
}
318310
}
319-
320-
if (deleteDirectories.Count > 0)
321-
{
322-
return deleteDirectories.ToArray();
323-
}
324311
}
325-
return null;
326312
}
327313

328314
private string CreateFileName(string file)

0 commit comments

Comments
 (0)