-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileManager.cs
78 lines (60 loc) · 2.34 KB
/
FileManager.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
using System.Threading;
using System.IO;
using System;
namespace FileRewriter_Threading_
{
partial class Form1 : IDisposable
{
public void RewriteFile(string path, string oldWord, string newWord, Replacer.Replace replace)
{
new Thread(() =>
{
if (File.Exists(path))
{
Loger.MakeLog("start working with "+path);
string[] lines = File.ReadAllLines(path);
int linesNumber= lines.Length;
LoadForm loadForm = new LoadForm();
loadForm.FileNameLabel.Text = path;
loadForm.progressBar.Maximum = linesNumber;
loadForm.Show();
loadForm.Refresh();
for (int i=0; i < linesNumber; i++)
{
lines[i] = replace(lines[i], oldWord, newWord);
lines[i] += " ";
i++;
loadForm.progressBar.Value += 1;
Thread.Sleep(1);//для наочності
}
File.WriteAllLines(path.Insert(path.LastIndexOf("."), "(Copy)"), lines);
Loger.MakeLog("data saved in "+path.Insert(path.LastIndexOf("."), "(Copy)"));
while (loadForm.progressBar.Value < loadForm.progressBar.Maximum)
{
loadForm.progressBar.Value += 1;
}
loadForm.CloseButton.Visible = true;
loadForm.Visible=false;
loadForm.ShowDialog();
loadForm.Dispose();
}
else throw new Exception("Error: File not found");
}).Start();
}
/*public FileInfo this[string path]
{
get
{
return files[files.IndexOf(new FileInfo(path))];
}
}*/
public new void Dispose()
{
/*foreach (Thread thread in threads)
{
if (thread.IsAlive) thread.Abort();
}*/
GC.SuppressFinalize(this);
}
}
}