-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form1.cs
92 lines (74 loc) · 2.94 KB
/
Form1.cs
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
81
82
83
84
85
86
87
88
89
90
91
92
using Ionic.Zip;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ComicCreator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Iterate through Source
//System.IO.DirectoryInfo = BN
//var _SubFolders = System.IO.Directory.GetDirectories(@"D:\ComicDL\Psycho Pass Kanshikan Kougami Shinya");
string _Path = txbxPath.Text;
var _SubFolders = System.IO.Directory.GetDirectories(_Path);
string _FolderName = System.IO.Path.GetFileName(_Path);
foreach (string _SubFolder in _SubFolders)
{
this.RenameFiles(_SubFolder);
using (ZipFile zip = new ZipFile())
{
//zip.AddDirectory(@"D:\ComicDL\Aoki Hagane No Arpeggio\Chapter 001");
zip.AddDirectory(_SubFolder);
string _OutputFullPath = @"D:\ComicDL\~Output\" + _FolderName + " - " + System.IO.Path.GetFileName(_SubFolder) + ".cbz";
zip.Save(_OutputFullPath);
}
}
MessageBox.Show("Done");
} //button1_Click
private void RenameFiles(string _SubFolder)
{
string[] _FilePaths = Directory.GetFiles(_SubFolder);
int _MaxFileLength = this.GetMaxNameLength(_FilePaths);
foreach (string _InitialFilePath in _FilePaths)
{
string _NameWithoutExtention = System.IO.Path.GetFileNameWithoutExtension(_InitialFilePath);
string _Extention = Path.GetExtension(_InitialFilePath);
int _Length = _NameWithoutExtention.Length;
if (_Length < _MaxFileLength)
{
string _Destination = _SubFolder + "\\" + new string('0', _MaxFileLength - _Length) + _NameWithoutExtention + _Extention;
File.Move(_InitialFilePath, _Destination);
}
}
//Just incase renames are still being done before zipping.
System.Threading.Thread.Sleep(1000);
} //RenameFiles
private int GetMaxNameLength(string[] filePaths)
{
// Convert this to LINQ?
int _MaxLength = 0;
foreach (string _InitialFilePath in filePaths)
{
string _NameWithoutExtention = System.IO.Path.GetFileNameWithoutExtension(_InitialFilePath);
if (_NameWithoutExtention.Length > _MaxLength)
{
_MaxLength = _NameWithoutExtention.Length;
}
}
return _MaxLength;
} //GetMaxNameLength
}
}