-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainForm.cs
979 lines (835 loc) · 32.8 KB
/
MainForm.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace FileExplorer
{
public partial class Form1 : Form
{
static int key = 5;
public static string Nuutsal(string Message)
{
String Message1 = String.Empty;
foreach (Char a in Message)
{
Message1 += (Char)(a + key);
}
return Message1;
}
public static string Nuutslal_garga(string Message)
{
String Message1 = String.Empty;
foreach (Char a in Message)
{
Message1 += (Char)(a - key);
}
return Message1;
}
public static String t1;
public static String Display1(Node n, String a, String b)
{
if (n != null)
{
int a1 = 0;
if (n.hus().Item1.CompareTo(a) == 0)
{
t1 = b;
return b;
}
Display1(n.leftLeaf, a, b + "0");
Display1(n.rightLeaf, a, b + "1");
return t1;
}
return null;
}
public static string str;
public static string strs;
public static string strs1;
public static Dictionary<String, int> Dawtamj = new Dictionary<String, int>();
public static Dictionary<String, String> Code_hus = new Dictionary<String, String>();
private const int BYTE_IN_KILOBYTE = 1024;
private const int COLUMN_WIDTH = 120;
private const int chir_zai = 10;
private string topLevelName = "Компьютер";
private string[] viewModes = { "Том зураг", "Жижиг зураг", "Жагсаалт", "Дэлгэрэнгүй" };
private Dictionary<string, int> columnsFiles = new Dictionary<string, int>();
private Dictionary<string, int> columnsDrives = new Dictionary<string, int>();
private string[] columnsForFiles = { "Нэр", "Хэмжээ", "Үүссэн огноо", "Огноо өөрчлөгдсөн" };
private string[] columnsForDrives = { "Нэр", "Төрөл", "Файлын систем", "Нийт хэмжээ", "Үлдсэн зай" };
private List<FileSystemInfo> fileSystemItems = new List<FileSystemInfo>();
private zurag zurag = new zurag();
public static int He=0;
private chireh chir = new chireh();
public void reset()
{
t1 = String.Empty;
str = String.Empty;
strs = String.Empty;
strs1 = String.Empty;
Dawtamj.Clear();
Code_hus.Clear();
}
public bool readFile1()
{
if (str != null)
{
if (str.Contains(".pjl"))
{
using (StreamReader reader = new StreamReader(str))
{
string line = reader.ReadLine();
He = Int32.Parse(Nuutslal_garga(line));
for (int i = 0; i < He; i++)
{
line = Nuutslal_garga(reader.ReadLine());
string[] words;
words = line.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries);
Code_hus.Add(words[0],words[1]);
}
while (true)
{
String line1 = reader.ReadLine();
if (line1 == null)
{
break;
}
line = Nuutslal_garga(line1);
strs1 = strs1 + line;
//Console.WriteLine(Nuutslal_garga(line));
}
}
return true;
}
else return false;
}
else return false;
}
public bool readFile()
{
if (str != null)
{
if (str.Contains(".txt"))
{
using (StreamReader reader = new StreamReader(str))
{
while (true)
{
string line = reader.ReadLine();
if (line == null)
{
break;
}
strs = strs + line;
//Console.WriteLine(Nuutslal_garga(line));
}
}
return true;
}
else return false;
}
else return false;
}
String shine;
public int bintodec(String a)
{
return Convert.ToInt32(a, 2) ;
}
public String dectobin(string a)
{
int a1 = Int32.Parse(a);
return Convert.ToString(a1, 2);
}
public static string zad;
public void zadal()
{
if (readFile1() == true)
{
String ner = str.Substring(0, str.Length - 4) + "1.txt";
using (StreamWriter writer = new StreamWriter(ner))
{
for(int i = 0; i < strs1.Length; i++)
{
String a3;
char aa3 = strs1[i];
int aaaa3 = aa3;
String aaa3 = aaaa3.ToString();
a3 = dectobin(aaa3);
a3 = a3.PadLeft(8, '0');
zad = zad + a3;
// writer.Write(dectobin("180"));
}
for(int i=0;i<zad.Length;i++)
{
// label1.Text = String.Empty;
foreach (KeyValuePair<String, String> kvp in Code_hus)
{
//label1.Text = strs1;
if (zad.Substring(i).IndexOf(kvp.Value)==0)
{
if(kvp.Key.CompareTo("*")==0)
writer.Write(" ");
else writer.Write(kvp.Key);
i = i + kvp.Value.Length-1;
break;
label1.Text = label1.Text + kvp.Key;
}
}
// writer.Write("puujee");
}
}
}
}
public void shah()
{
if (readFile() == true)
{
//Console.WriteLine(str);
foreach (char currentChar in strs)
{
if (Dawtamj.ContainsKey(currentChar.ToString()))
{ Dawtamj[currentChar.ToString()]++; }
else
{ Dawtamj.Add(currentChar.ToString(), 1); }
}
daraalal dar = new daraalal();
foreach (KeyValuePair<String, int> kvp in Dawtamj)
{
BinaryTree b = new BinaryTree();
b.insert(Tuple.Create(kvp.Key, kvp.Value));
dar.oruul(b);
}
dar.Uusge();
foreach (KeyValuePair<String, int> kvp in Dawtamj)
{
if (kvp.Key.CompareTo(" ") == 0)
Code_hus.Add("*", Display1(dar.asdqwe().root1(), kvp.Key, ""));
else
Code_hus.Add(kvp.Key, Display1(dar.asdqwe().root1(), kvp.Key, ""));
}
String ner = str.Substring(0, str.Length - 4) + ".pjl";
using (StreamWriter writer = new StreamWriter(ner))
{
writer.Write(Nuutsal(Code_hus.Count.ToString()) +"\n");
foreach (KeyValuePair<String, String> kvp in Code_hus)
{
writer.Write(Nuutsal(kvp.Key + " " + kvp.Value) + "\n");
//Console.WriteLine("Code {0}:\t{1}", kvp.Key, kvp.Value);
// richTextBox1.Text = richTextBox1.Text + kvp.Key + " " + kvp.Value + "\n";
}
for (int i = 0; i < strs.Length; i++)
{
if (strs.Substring(i, 1).CompareTo(" ") == 0)
{
String code = Code_hus["*"];
shine = shine + code;//.PadLeft(6,'0');
}
else {
String code = Code_hus[strs.Substring(i, 1)];
shine = shine + code;
}
}
for(int i = 0; i < shine.Length; i = i + 8)
{
String a;
if (shine.Length - i < 8) a = shine.Substring(i, shine.Length - i);
else a = shine.Substring(i, 8);
String baa = bintodec(a).ToString();
//baa = baa.PadLeft(3, '0');
int baa1 = Int32.Parse(baa);
char baa3 = (char)baa1;
String baa2 = baa3.ToString();
writer.Write(Nuutsal(baa2));
}
}
}
else
{
MessageBox.Show( "Та .txt өргөтгөлтэй файл сонгоно уу?","Алдаа" ,MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public Form1()
{
InitializeComponent();
Application.ThreadException += Application_ThreadException;
foreach (string column in columnsForFiles)
{
columnsFiles.Add(column, COLUMN_WIDTH);
}
foreach (string column in columnsForDrives)
{
columnsDrives.Add(column, COLUMN_WIDTH);
}
foreach (string item in viewModes)
{
toolStripComboBox1.Items.Add(item);
}
toolStripComboBox1.SelectedIndex = 0;
toolStripComboBox1.SelectedIndexChanged += toolStripComboBox1_SelectedIndexChanged;
lv_files.MouseDoubleClick += lv_files_MouseDoubleClick;
lv_files.ColumnClick += lv_files_ColumnClick;
lv_files.View = View.LargeIcon;
tsl_path.Text = topLevelName;
tv_files.BeforeExpand += tv_files_BeforeExpand;
tv_files.AfterSelect += tv_files_AfterSelect;
tv_files.AfterLabelEdit += tv_files_AfterLabelEdit;
lv_files.MouseDown += lv_files_MouseDown;
lv_files.MouseMove += lv_files_MouseMove;
lv_files.DragEnter += lv_files_DragEnter;
lv_files.DragLeave += lv_files_DragLeave;
lv_files.DragDrop += lv_files_DragDrop;
lv_files.QueryContinueDrag += lv_files_QueryContinueDrag;
}
private void Form1_Load(object sender, EventArgs e)
{
ShowDrives();
}
void lv_files_MouseDown(object sender, MouseEventArgs e)
{
ListViewItem currentItem = lv_files.GetItemAt(e.X, e.Y);
if (currentItem != null)
{
currentItem.Selected = true;
chir.isSelected = true;
chir.startPositionPoint.X = e.X;
chir.startPositionPoint.Y = e.Y;
}
}
void lv_files_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left && chir.isSelected)
{
chir.currentPositionPoint.X = e.X;
chir.currentPositionPoint.Y = e.Y;
if (chir.GetDistance() >= chir_zai)
{
ListViewItem currentLvi = lv_files.GetItemAt(e.X, e.Y);
if (currentLvi == null)
{
return;
}
lv_files.DoDragDrop(currentLvi, DragDropEffects.Move);
chir.isDrag = true;
}
}
}
void lv_files_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
void lv_files_DragLeave(object sender, EventArgs e)
{
chir.isDrag = false;
}
void lv_files_DragDrop(object sender, DragEventArgs e)
{
chir = new chireh();
Point clPoint = lv_files.PointToClient(new Point(e.X, e.Y));
ListViewItem destItem = lv_files.GetItemAt(clPoint.X, clPoint.Y);
if (destItem != null)
{
DirectoryInfo destDirectory = destItem.Tag as DirectoryInfo;
if (destDirectory == null)
{
return;
}
else
{
ListViewItem tempLvi = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
FileSystemInfo tempFsi = (FileSystemInfo)tempLvi.Tag;
DirectoryInfo tempDi = tempFsi as DirectoryInfo;
if (tempDi != null)
{
if (tempDi == destDirectory)
{
return;
}
}
}
ListViewItem srcItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem));
FileSystemInfo srcFileSystemItem = srcItem.Tag as FileSystemInfo;
string newPath = Path.Combine(destDirectory.FullName, srcFileSystemItem.Name);
if (MoveFileObject(srcFileSystemItem, newPath))
{
if (SetFileSystemItems(tsl_path.Text))
{
ShowFileSystemItems();
}
tv_files.SelectedNode.Collapse();
tv_files.SelectedNode.Expand();
}
}
}
void lv_files_QueryContinueDrag(object sender, QueryContinueDragEventArgs e)
{
if (!chir.isDrag)
{
e.Action = DragAction.Cancel;
}
}
void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.Message, "Алдаа", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (toolStripComboBox1.SelectedItem.ToString())
{
case "Том зураг":
lv_files.View = View.LargeIcon;
break;
case "Жижиг зураг":
lv_files.View = View.SmallIcon;
break;
case "Дэлгэрэнгүй":
lv_files.View = View.Details;
lv_files.FullRowSelect = true;
break;
case "Жагсаалт":
lv_files.View = View.List;
break;
default:
MessageBox.Show("Ийм горим байхгүй", "Алдаа", MessageBoxButtons.OK, MessageBoxIcon.Error);
break;
}
}
void lv_files_MouseDoubleClick(object sender, MouseEventArgs e)
{
ListViewItem selection = lv_files.GetItemAt(e.X, e.Y);
object tag = selection.Tag;
if (tag is FileInfo)
{
str = ((FileInfo)tag).FullName;
label1.Text = ((FileInfo)tag).FullName;
return;
}
string path = null;
if (tag is DriveInfo)
{
path = ((DriveInfo)tag).RootDirectory.ToString();
}
else if (tag is DirectoryInfo)
{
path = ((DirectoryInfo)tag).FullName;
}
if (SetFileSystemItems(path))
{
ShowFileSystemItems();
tsl_path.Text = path;
ShowPathInTree(path);
}
}
void tsb_upLevel_Click(object sender, EventArgs e)
{
string path = tsl_path.Text;
if (path == topLevelName)
{
return;
}
DirectoryInfo currentDirectory = new DirectoryInfo(path);
DirectoryInfo parentDirectory = currentDirectory.Parent;
if (parentDirectory != null)
{
SetFileSystemItems(parentDirectory.FullName);
ShowFileSystemItems();
tsl_path.Text = parentDirectory.FullName;
ShowPathInTree(tsl_path.Text);
}
else
{
ShowDrives();
}
}
void lv_files_ColumnClick(object sender, ColumnClickEventArgs e)
{
if (tsl_path.Text == topLevelName)
{
return;
}
int currentColumn = e.Column;
hartsuul currentComparer = (hartsuul)lv_files.ListViewItemSorter;
if (currentComparer == null)
{
currentComparer = new hartsuul();
}
if (currentColumn == currentComparer.columnIndex)
{
if (currentComparer.sortOrder == hartsuul.SORTORDER.ASC)
{
currentComparer.sortOrder = hartsuul.SORTORDER.DESC;
lv_files.Columns[currentColumn].ImageIndex = 3;
}
else
{
currentComparer.sortOrder = hartsuul.SORTORDER.ASC;
lv_files.Columns[currentColumn].ImageIndex = 2;
}
}
else
{
lv_files.Columns[currentComparer.columnIndex].ImageIndex = -1;
lv_files.Columns[currentComparer.columnIndex].TextAlign = HorizontalAlignment.Center;
lv_files.Columns[currentComparer.columnIndex].TextAlign = HorizontalAlignment.Left;
currentComparer.columnIndex = currentColumn;
currentComparer.sortOrder = hartsuul.SORTORDER.ASC;
lv_files.Columns[currentColumn].ImageIndex = 2;
}
lv_files.ListViewItemSorter = currentComparer;
lv_files.Sort();
}
void tv_files_BeforeExpand(object sender, TreeViewCancelEventArgs e)
{
TreeNode currentNode = e.Node;
currentNode.Nodes.Clear();
string[] directories = Directory.GetDirectories(currentNode.FullPath);
foreach (string directory in directories)
{
TreeNode t = new TreeNode(Path.GetFileName(directory), 0, 1);
currentNode.Nodes.Add(t);
try
{
string[] a = Directory.GetDirectories(directory);
if (a.Length > 0)
{
t.Nodes.Add("?");
}
}
catch { }
}
}
void tv_files_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeNode selectedNode = e.Node;
string currentPath = e.Node.FullPath;
selectedNode.Expand();
if (SetFileSystemItems(currentPath))
{
ShowFileSystemItems();
tsl_path.Text = currentPath;
}
else
{
ShowPathInTree(tsl_path.Text);
}
}
void tv_files_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
string currentPath = e.Node.FullPath;
string newDirectoryName = e.Label;
if (newDirectoryName == null || newDirectoryName.Trim().Length == 0)
{
e.CancelEdit = true;
return;
}
string newFullName = Path.Combine(e.Node.Parent.FullPath, newDirectoryName);
DirectoryInfo currentDirectory = new DirectoryInfo(currentPath);
try
{
currentDirectory.MoveTo(newFullName);
if (SetFileSystemItems(newFullName))
{
ShowFileSystemItems();
tsl_path.Text = newFullName;
}
}
catch
{
MessageBox.Show("Алдаа гарлаа", "Алдаа", MessageBoxButtons.OK, MessageBoxIcon.Information);
e.CancelEdit = true;
}
}
public bool SetFileSystemItems(string path)
{
try
{
string[] access = Directory.GetDirectories(path);
}
catch
{
MessageBox.Show("Алдаа гарлаа", "Алдаа", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
if (fileSystemItems != null && fileSystemItems.Count != 0)
{
fileSystemItems.Clear();
}
string[] directories = Directory.GetDirectories(path);
foreach (string directory in directories)
{
DirectoryInfo di = new DirectoryInfo(directory);
fileSystemItems.Add(di);
}
string[] files = Directory.GetFiles(path);
foreach (string file in files)
{
FileInfo fi = new FileInfo(file);
fileSystemItems.Add(fi);
}
return true;
}
private void ShowFileSystemItems()
{
lv_files.BeginUpdate();
lv_files.Items.Clear();
if (fileSystemItems == null || fileSystemItems.Count == 0)
{
return;
}
SetColumsForFolders();
zurag.ClearIconCashAndLists(il_DiscFoldersFilesIcons_Small, il_DiscFoldersFilesIcons_Large);
ListViewItem lviFile = null;
foreach (FileSystemInfo file in fileSystemItems)
{
lviFile = new ListViewItem();
lviFile.Tag = file;
lviFile.Text = file.Name;
if (file is DirectoryInfo)
{
lviFile.ImageIndex = 1;
lviFile.SubItems.Add("Хавтас");
}
else if (file is FileInfo)
{
FileInfo currentFile = file as FileInfo;
if (currentFile == null)
{
return;
}
string fileExtention = currentFile.Extension.ToLower();
int iconIndex = zurag.GetIconIndexByExtention(fileExtention);
if (iconIndex != -1)
{
lviFile.ImageIndex = iconIndex;
}
else
{
lviFile.ImageIndex = zurag.AddIconForFile((FileInfo)file, il_DiscFoldersFilesIcons_Small, il_DiscFoldersFilesIcons_Large);
}
lviFile.SubItems.Add(((FileInfo)file).Length.ToString());
}
lviFile.SubItems.Add(file.CreationTime.ToString());
lviFile.SubItems.Add(file.LastWriteTime.ToString());
lv_files.Items.Add(lviFile);
lv_files.EndUpdate();
}
}
private void ShowDrives()
{
tsl_path.Text = topLevelName;
if (lv_files != null && lv_files.Items.Count != 0)
{
lv_files.Items.Clear();
}
if (tv_files != null && tv_files.Nodes.Count != 0)
{
tv_files.Nodes.Clear();
}
DriveInfo[] discs = DriveInfo.GetDrives();
if (discs.Length == 0)
{
MessageBox.Show("Диск олдсонгүй", "Анхааруулга", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
SetColumsForDrives();
ListViewItem lviDisc;
foreach (DriveInfo disc in discs)
{
if (disc.IsReady)
{
string totalSize = String.Format("{0:F2} GB", (double)disc.TotalSize / (BYTE_IN_KILOBYTE * BYTE_IN_KILOBYTE * BYTE_IN_KILOBYTE)); //в Гб
string freeSpace = String.Format("{0:F2} GB", (double)disc.TotalFreeSpace / (BYTE_IN_KILOBYTE * BYTE_IN_KILOBYTE * BYTE_IN_KILOBYTE)); //в Гб
lviDisc = new ListViewItem(disc.Name, 0);
lviDisc.SubItems.Add(disc.DriveType.ToString());
lviDisc.SubItems.Add(disc.DriveFormat.ToString());
lviDisc.SubItems.Add(totalSize);
lviDisc.SubItems.Add(freeSpace);
lviDisc.Tag = disc;
lv_files.Items.Add(lviDisc);
}
}
foreach (DriveInfo disc in discs)
{
if(disc.IsReady)
{
TreeNode tnDisc = new TreeNode(disc.Name, 2, 2);
tv_files.Nodes.Add(tnDisc);
try
{
string[] directoriesInDisc = Directory.GetDirectories(disc.RootDirectory.ToString());
if (directoriesInDisc.Length > 0)
{
TreeNode tempNode = new TreeNode("?");
tnDisc.Nodes.Add(tempNode);
}
}
catch { }
}
}
}
private void ShowPathInTree(string path)
{
string[] directories = path.Split('\\');
string root = Path.GetPathRoot(path);
TreeNode currentNode = null;
foreach (TreeNode treeNode in tv_files.Nodes)
{
if (treeNode.Text == root)
{
treeNode.Expand();
currentNode = treeNode;
break;
}
}
for (int i = 1; i < directories.Length; i++)
{
if (directories[i].Length == 0)
{
continue;
}
foreach (TreeNode treeNode in currentNode.Nodes)
{
if (treeNode.Text == directories[i])
{
treeNode.Expand();
currentNode = treeNode;
}
}
}
tv_files.SelectedNode = currentNode;
}
private bool MoveFileObject(FileSystemInfo fsObject, string newPath)
{
string message = "";
try
{
if (fsObject is DirectoryInfo)
{
message = "Алдаа гарлаа";
((DirectoryInfo)fsObject).MoveTo(newPath);
}
else
{
message = "Файлыг зөөх боломжгүй байна";
((FileInfo)fsObject).MoveTo(newPath);
}
return true;
}
catch
{
MessageBox.Show(message, "Анхааруулга", MessageBoxButtons.OK, MessageBoxIcon.Information);
return false;
}
}
private void SetColumsForDrives()
{
if (lv_files.Columns.Count != 0)
{
lv_files.Columns.Clear();
}
ColumnHeader column = null;
foreach (KeyValuePair<string, int> item in columnsDrives)
{
column = new ColumnHeader();
column.Text = item.Key;
column.Width = item.Value;
column.TextAlign = HorizontalAlignment.Left;
lv_files.Columns.Add(column);
}
}
private void SetColumsForFolders()
{
if (lv_files.Columns.Count != 0)
{
lv_files.Columns.Clear();
}
int sortedColumnIndex = 0;
hartsuul.SORTORDER sortOrder = hartsuul.SORTORDER.ASC;
hartsuul currentComparer = (hartsuul)lv_files.ListViewItemSorter;
if (currentComparer != null)
{
sortedColumnIndex = currentComparer.columnIndex;
sortOrder = currentComparer.sortOrder;
}
ColumnHeader column = null;
int currentColumnIndex = 0;
foreach (KeyValuePair<string, int> item in columnsFiles)
{
column = new ColumnHeader();
column.Text = item.Key;
column.Width = item.Value;
if (sortedColumnIndex == currentColumnIndex)
{
if (sortOrder == hartsuul.SORTORDER.ASC)
{
column.ImageIndex = 2;
}
else
{
column.ImageIndex = 3;
}
}
lv_files.Columns.Add(column);
currentColumnIndex++;
}
}
private void tv_files_AfterSelect_1(object sender, TreeViewEventArgs e)
{
}
private void splitContainer1_Panel2_Paint(object sender, PaintEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
shah();
reset();
string path = tsl_path.Text;
if (path == topLevelName)
{
return;
}
DirectoryInfo parentDirectory = new DirectoryInfo(path);
if (parentDirectory != null)
{
SetFileSystemItems(parentDirectory.FullName);
ShowFileSystemItems();
tsl_path.Text = parentDirectory.FullName;
ShowPathInTree(tsl_path.Text);
}
else
{
ShowDrives();
}
}
private void button2_Click(object sender, EventArgs e)
{
zadal();
reset();
string path = tsl_path.Text;
if (path == topLevelName)
{
return;
}
DirectoryInfo parentDirectory = new DirectoryInfo(path);
if (parentDirectory != null)
{
SetFileSystemItems(parentDirectory.FullName);
ShowFileSystemItems();
tsl_path.Text = parentDirectory.FullName;
ShowPathInTree(tsl_path.Text);
}
else
{
ShowDrives();
}
}
private void toolStripComboBox1_Click(object sender, EventArgs e)
{
}
}
}