-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathElfFileListGetter.cs
121 lines (103 loc) · 3.56 KB
/
ElfFileListGetter.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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
namespace ESPEDfGK
{
//*****************************************************************************************
// next step: c# wpf add tooltip for combobox item
internal class FileListItem : INotifyPropertyChanged
{
public string FileName { get; set; }
public DateTime LastChange { get; set; }
public event PropertyChangedEventHandler? PropertyChanged;
public override string ToString()
{
return FileName;
}
}
//*****************************************************************************************
internal class ElfListGetter
{
//*****************************************************************************************
string SketchFolder()
{
string p = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
+ Path.DirectorySeparatorChar + StringContent.arduinoclisettings;
string[] content = File.ReadAllLines(p);
/*
downloads: c:\Users\holger2\AppData\Local\Arduino15\staging
user: d:\Arduino\sketches2.0
*/
for (int i = 0; i < content.Length; i++)
{
int j = content[i].IndexOf("user:");
if (j > 0)
{
string s = content[i].Substring(j + 5);
return s.Trim();
}
}
return ""; // nix gefunden
}
//*****************************************************************************************
string TempFolder()
{
return Path.GetTempPath();
}
//*****************************************************************************************
public ObservableCollection<FileListItem> GetFileList(bool usesketchfolder, bool usetempfolder)
{
ObservableCollection<FileListItem> res = new();
List<string> pl = new();
if (usesketchfolder)
{
pl.Add(SketchFolder());
}
if (usetempfolder)
{
pl.Add(TempFolder());
}
if (pl.Count==0) // stupid configuration, no location selected... ?
{
pl.Add(SketchFolder());
pl.Add(TempFolder());
}
foreach (string p in pl)
{
try
{
string[] files = Directory.GetFiles(p, StringContent.elffilepattern, SearchOption.AllDirectories);
foreach (string f in files)
{
FileListItem item = new();
item.FileName = f;
item.LastChange = File.GetLastWriteTime(f);
res.Add(item);
}
}
catch
{
//;
}
}
if (res.Count > 1)
{
int i = 0;
DateTime md = res[i].LastChange;
for (int j = 1; j < res.Count; j++)
{
if (res[j].LastChange > md)
{
md = res[j].LastChange;
i = j;
}
}
res.Insert(0, res[i]);
res.RemoveAt(i+1);
}
return res;
}
}
}