001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.ComponentModel;
004.
using
System.Data;
005.
using
System.Drawing;
006.
using
System.Linq;
007.
using
System.Text;
008.
using
System.Windows.Forms;
009.
010.
namespace
CheckFileNCN
011.
{
012.
public
partial
class
frmCheckFileNCN : Form
013.
{
014.
public
frmCheckFileNCN()
015.
{
016.
InitializeComponent();
017.
}
018.
019.
int
sngPer =0, sngRun = 0;
020.
double
startCounter;
021.
List<
string
> list;
022.
string
PathKARA;
023.
int
maxThread = 26;
024.
int
ChkThread;
025.
void
GetNCN()
026.
{
027.
list =
new
List<
string
>();
028.
System.Collections.Generic.Stack<
string
> stack =
new
System.Collections.Generic.Stack<
string
>();
029.
stack.Push(txtSouce.Text);
030.
031.
while
((stack.Count > 0))
032.
{
033.
string
dir = stack.Pop();
034.
list.AddRange(System.IO.Directory.GetFiles(dir,
"*.lyr"
));
035.
this
.Invoke(
new
Action(() =>{
this
.Text =
"Check Folder "
+ dir;})) ;
036.
lblEMKDetail.Invoke(
new
Action(() => {lblEMKDetail.Text=
"NCN File; "
+ (list.Count - 1); })) ;
037.
string
directoryName =
null
;
038.
foreach
(
string
directoryName_loopVariable
in
System.IO.Directory.GetDirectories(dir))
039.
{
040.
directoryName = directoryName_loopVariable;
041.
stack.Push(directoryName);
042.
}
043.
}
044.
if
(list.Count - 1 < 1) { Text =
"Complete ..."
;
return
; }
045.
sngPer = (list.Count - 1) / 26;
046.
progressBar2.Invoke(
new
Action(() => { progressBar2.Maximum = list.Count - 1; }));
047.
PathKARA = txtTarget.Text;
048.
startCounter = DateTime.Now.TimeOfDay.TotalSeconds;
049.
ChkThread = 0;
050.
for
(
int
i = 0; i < maxThread; i++)
051.
{
052.
new
System.Threading.Thread(CheckFile).Start(
new
object
[] { Convert.ToChar(65 + i).ToString(), i * sngPer, (i + 1) * sngPer - 1 });
053.
}
054.
055.
}
056.
#region _Select path
057.
private
void
button4_Click(
object
sender, EventArgs e)
058.
{
059.
System.Threading.Thread Thd =
new
System.Threading.Thread(
new
System.Threading.ThreadStart(GetNCN)) { IsBackground =
true
};
060.
Thd.Start();
061.
}
062.
private
void
button1_Click(
object
sender, EventArgs e)
063.
{
064.
FolderBrowserDialog fd =
new
FolderBrowserDialog();
065.
fd.ShowDialog();
066.
txtSouce.Text = fd.SelectedPath;
067.
}
068.
069.
private
void
button2_Click(
object
sender, EventArgs e)
070.
{
071.
FolderBrowserDialog fd =
new
FolderBrowserDialog();
072.
fd.ShowDialog();
073.
txtTarget.Text = fd.SelectedPath;
074.
}
075.
#endregion
076.
077.
private
void
frmCheckFileNCN_Load(
object
sender, EventArgs e)
078.
{
079.
080.
081.
082.
}
083.
084.
private
void
CheckFile(
object
obj)
085.
{
086.
string
Fol_Lyrics, Fol_Song, Fol_Cursor;
087.
string
s_S =
""
;
string
t_S =
""
;
088.
string
s_L =
""
;
string
t_L =
""
;
089.
string
s_C =
""
;
string
t_C =
""
;
090.
int
_sngNCN = 0;
091.
string
FolderCode = (
string
)((
object
[])obj)[0];
092.
int
min = (
int
)((
object
[])obj)[1];
093.
int
max = (
int
)((
object
[])obj)[2];
094.
int
i = min;
095.
096.
Fol_Lyrics = PathKARA +
"\\Songs\\MIDI\\NCN\\Lyrics\\"
+ FolderCode;
097.
Fol_Song = PathKARA +
"\\Songs\\MIDI\\NCN\\Song\\"
+ FolderCode;
098.
Fol_Cursor = PathKARA +
"\\Songs\\MIDI\\NCN\\Cursor\\"
+ FolderCode;
099.
MIDI_Dll.MIDI_Dll.CreatePath(Fol_Song);
100.
MIDI_Dll.MIDI_Dll.CreatePath(Fol_Lyrics);
101.
MIDI_Dll.MIDI_Dll.CreatePath(Fol_Cursor);
102.
103.
while
(
true
)
104.
{
105.
106.
s_L = list[i].ToLower();
107.
s_S = s_L.Replace(
"\\lyrics\\", "
\\song\\
").Replace("
.lyr
", "
.mid");
108.
s_C = s_L.Replace(
"\\lyrics\\", "
\\cursor\\
").Replace("
.lyr
", "
.cur");
109.
if
(System.IO.File.Exists(s_C) && System.IO.File.Exists(s_S))
110.
{
111.
112.
do
113.
{
114.
t_S = Fol_Song +
"\\" + FolderCode + string.Format("
{0:00000}
", _sngNCN) + "
.mid";
115.
t_C = Fol_Cursor +
"\\" + FolderCode + string.Format("
{0:00000}
", _sngNCN) + "
.cur";
116.
t_L = Fol_Lyrics +
"\\" + FolderCode + string.Format("
{0:00000}
", _sngNCN) + "
.lyr";
117.
_sngNCN++;
118.
}
while
(System.IO.File.Exists(t_L) || System.IO.File.Exists(t_C) || System.IO.File.Exists(t_S));
119.
120.
121.
System.IO.File.Move(s_S, t_S);
122.
System.IO.File.Move(s_C, t_C);
123.
System.IO.File.Move(s_L, t_L);
124.
125.
126.
}
127.
128.
129.
130.
try
131.
{
132.
133.
if
(sngRun > 0)
134.
{
135.
double
t = DateTime.Now.TimeOfDay.TotalSeconds - startCounter;
136.
double
strt = (
double
)((list.Count - sngRun) * t / sngRun);
137.
this
.lblEMKDetail.Invoke(
new
Action(() =>
138.
{
139.
this
.lblEMKDetail.Text =
"Check File "
+ s_S + Environment.NewLine + t_S + Environment.NewLine +
140.
"File: "
+ sngRun +
"/"
+ (list.Count - 1) + Environment.NewLine +
141.
"Completion Ratio:"
+
string
.Format(
"{0:0.0000}"
, Convert.ToDouble(100 * (
double
)sngRun / (
double
)(list.Count - 1))) +
" %"
+ Environment.NewLine +
142.
"Speed:"
+
string
.Format(
"{0:0.00}"
, ((
double
)sngRun / t)) +
"file/s"
+ Environment.NewLine +
143.
"Elapsed time:"
+ MIDI_Dll.MIDI_Dll.Time(t) + Environment.NewLine +
144.
"Remaining time:"
+ MIDI_Dll.MIDI_Dll.Time(strt);
145.
}));
146.
147.
}
148.
this
.progressBar2.Invoke(
new
Action(() => {
this
.progressBar2.Value = sngRun; }));
149.
}
150.
catch
{ }
151.
sngRun++;
152.
System.Threading.Thread.Sleep(5);
153.
154.
i++;
155.
if
(i >= max)
156.
{
157.
ChkThread++;
158.
if
(ChkThread > maxThread && checkBox1.Checked ==
true
)
159.
{
160.
System.Diagnostics.Process.Start(
new
System.Diagnostics.ProcessStartInfo(
"shutdown.exe"
,
"-s"
));
161.
}
162.
else
163.
{
return
; }
164.
}
165.
}
166.
167.
168.
}
169.
170.
}
171.
}