-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfileio.ahk
54 lines (42 loc) · 951 Bytes
/
fileio.ahk
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
Save_Shape(data, path) {
FileDelete, % Path
output := "", bloc
Loop, % data.MaxIndex() {
output .= data[A_index][1] . " " . data[A_index][2] . ", "
}
FileAppend, % output, % Path
If (ErrorLevel)
Return -1
Return 0
}
Load_Shape(path) {
If (!FileExist(path))
Return -1
FileRead, string, % path
RegExNeedle := "([0-9]+) ([0-9]+),"
p0 := 1
shape := Array()
while p1 := RegExMatch(string, RegExNeedle, output, p0) {
shape[A_Index] := Array()
shape[A_Index][1] := output1
shape[A_Index][2] := output2
p0 := p1 + StrLen(output1) + 2 + StrLen(output2)
}
Return shape
}
Load_All(ByRef shapes, ByRef files) {
shapes := Array()
files := Array()
FileList =
Loop, shapes\*.txt
FileList = %FileList%%A_LoopFileName%`n
Sort, FileList
Loop, parse, FileList, `n
{
if A_LoopField =
continue
file := "shapes\" . A_LoopField
shapes[A_Index] := Load_Shape(file)
files[A_Index] := A_LoopField
}
}