-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_diff.bt
111 lines (99 loc) · 2.66 KB
/
image_diff.bt
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
//------------------------------------------------
//--- 010 Editor v10.0.1 Binary Template
//
// File:
// Authors:
// Version:
// Purpose:
// Category: smolsync
// File Mask: *.diff
// ID Bytes: 73 6d 6f 6c 64 69 66 66 //smoldiff
// History:
//------------------------------------------------
typedef struct {
int len;
if (len > 0)
char s[len];
} str <read=read_STRING>;
string read_STRING(local str &s) {
if (s.len == 0)
return "\"\"";
local string res = "";
SPrintf(res, "<%d> %s", s.len, s.s);
return res;
}
string read_SIZE(local int64 size_i) {
local string res = "";
local double size = size_i;
if (Abs(size) < 1024) {
SPrintf(res, "%Ld b", size);
}
local string units = "kmgtp";
local int unit = 0;
while (Abs(size) > 1024 && unit != 5) {
size /= 1024;
unit += 1;
}
SPrintf(res, "%.1lf %sb", size, SubStr(units, unit-1, 1));
return res;
}
string read_double_time(local double time) {
local string res = "";
SPrintf(res, "%lf", time - (int)time);
res = SubStr(res, 1);
SPrintf(res, "%s%s", TimeTToString((time_t)time), res);
return res;
}
typedef struct {
str name;
time_t modified;
int64 size <read=read_SIZE>;
double created <read=read_double_time>;
char hash[20];
} File <read=read_FILE>;
wstring read_FILE(local File &file) {
return StringToWString(file.name.s, CHARSET_UTF8);
}
typedef struct {
char status;
if (status == 'D') {
File old <open=true>;
} else if (status == 'A') {
File new <open=true>;
} else if (status == 'C') {
File new <open=true>;
str from_path;
} else if (status == 'M') {
File new <open=true>;
File old <open=true>;
} else if (status == '-') {
File new <open=true>;
}
} FileDiff;
wstring read_FILEDIFF(local FileDiff &file) {
local wstring res = "";
local string filename;
if (exists(file.new))
filename = file.new.name;
else
filename = file.old.name;
SPrintf(res, "%c %s", file.status, StringToWString(file.name.s, CHARSET_UTF8));
return res;
}
struct ImageDiff;
struct ImageDiff {
str name;
int64 copied_size <read=read_SIZE>;
int64 change_in_size <read=read_SIZE>;
uint files_count;
FileDiff files[files_count] <optimize=false>;
uint folder_count;
if (folder_count)
ImageDiff folders[folder_count] <optimize=false, read=read_FOLDER>;
};
wstring read_FOLDER(local ImageDiff &image) {
return StringToWString(image.name.s, CHARSET_UTF8);
}
char signature[8];
Assert(!Strcmp(signature, "smoldiff"), "signature is wrong");
ImageDiff root <open=true>;