Skip to content
This repository was archived by the owner on Mar 27, 2022. It is now read-only.

Commit 0a051dd

Browse files
committed
Refine feature
1 parent 8004cb0 commit 0a051dd

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

HayDayDecoder/Decoder.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99

1010
namespace HayDayDecoder
1111
{
12-
class Decoder
12+
public class Decoder
1313
{
1414
public Decoder() {}
1515

16-
public bool unzipDirectory(string dirPath)
16+
public IEnumerable<string> unzipDirectory(string dirPath)
1717
{
1818
string[] fileList = Directory.GetFiles(dirPath);
1919
foreach(string file in fileList)
@@ -22,28 +22,31 @@ public bool unzipDirectory(string dirPath)
2222
if (fileInfo.Extension != ".csv") continue;
2323

2424
// Unzip file
25-
if(unzipFile(file))
25+
string result;
26+
var unzipStatus = unzipFile(file, out result);
27+
28+
if (unzipStatus)
2629
{
2730
// Delete original file
2831
File.Delete(file);
29-
30-
System.Console.WriteLine("[Delete file]\t" + fileInfo.Name);
32+
result += "\n[Delete file]\t" + fileInfo.Name;
3133
}
34+
yield return result;
3235
}
33-
return true;
36+
yield break;
3437
}
3538

36-
public bool unzipFile(string filePath)
39+
public bool unzipFile(string filePath, out string result)
3740
{
3841
FileInfo fileInfo = new FileInfo(filePath);
3942

4043
// Step 1. Fix file
4144
fixFile(filePath, fileInfo);
4245

4346
// Step 2. Unzip file
47+
string outputPath = fileInfo.FullName.Replace(".csv", "_r.csv");
4448
try
4549
{
46-
string outputPath = fileInfo.FullName.Replace(".csv", "_r.csv");
4750
using (var input = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite))
4851
{
4952
var decoder = new LzmaDecodeStream(input);
@@ -61,11 +64,11 @@ public bool unzipFile(string filePath)
6164
}
6265
catch(Exception)
6366
{
64-
System.Console.WriteLine("[Broken file]\t" + fileInfo.Name);
67+
result = "[Broken file]\t" + fileInfo.Name;
68+
File.Delete(outputPath);
6569
return false;
6670
}
67-
68-
System.Console.WriteLine("[Unzip file]\t" + fileInfo.Name);
71+
result = "[Unzip file]\t" + fileInfo.Name;
6972
return true;
7073
}
7174

0 commit comments

Comments
 (0)