-
Notifications
You must be signed in to change notification settings - Fork 0
/
usettings.pas
197 lines (159 loc) · 4.84 KB
/
usettings.pas
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
unit usettings;
{$mode objfpc}{$H+}
interface
uses
SysUtils, IniFiles, Graphics;
type
{ TSettings }
TSettings = class
private
FIniFile: TIniFile;
procedure FTranspModeWrite(Value: Integer);
function FTranspModeRead(): Integer;
procedure FStretchModeWrite(Value: Boolean);
function FStretchModeRead(): Boolean;
procedure FLastDirWrite(const Value: string);
function FLastDirRead(): string;
procedure FBackColorWrite(Color: TColor);
function FBackColorRead(): TColor;
procedure FBitModeWrite(Mode: Integer);
function FBitModeRead(): Integer;
procedure FInfoVisibleWrite(Value: Boolean);
function FInfoVisibleRead(): Boolean;
{$IFDEF windows}
function FGetSendtoShortcutPath: WideString;
procedure FCreateSendtoShortcut;
function FSendtoShortcutExists: Boolean;
{$IFEND}
public
constructor Create(const DirPath: string);
destructor Destroy; override;
{$IFDEF windows}
procedure AddToSendTo(Delete: Boolean);
property SendToShortcutExists: Boolean read FSendtoShortcutExists;
{$IFEND}
property TranspMode: Integer read FTranspModeRead write FTranspModeWrite;
property StretchMode: Boolean read FStretchModeRead write FStretchModeWrite;
property LastDir: string read FLastDirRead write FLastDirWrite;
property BackColor: TColor read FBackColorRead write FBackColorWrite;
property BitMode: Integer read FBitModeRead write FBitModeWrite;
property InfoVisible: Boolean read FInfoVisibleRead write FInfoVisibleWrite;
end;
implementation
uses FileUtil
{$IFDEF windows}
,windows, shlobj {for special folders}, ActiveX, ComObj
{$ENDIF}
;
const
sMain = 'main';
sSendtoShortcut : string = 'Open in Tim2View';
{ TSettings }
procedure TSettings.AddToSendTo(Delete: Boolean);
{$IFDEF windows}
var
path: string;
begin
if Delete then
begin
path := UTF8Encode(FGetSendtoShortcutPath);
DeleteFile(PChar(Utf8ToSys(path)));
end
else
FCreateSendtoShortcut;
{$ELSE}
begin
{$ENDIF}
end;
{$IFDEF windows}
function TSettings.FGetSendtoShortcutPath: WideString;
var
PIDL: PItemIDList;
InFolder: array[0..MAX_PATH] of Char;
begin
SHGetSpecialFolderLocation(0, CSIDL_SENDTO, PIDL);
SHGetPathFromIDList(PIDL, InFolder);
Result := InFolder + PathDelim + UTF8ToSys(sSendtoShortcut)+'.lnk';
end;
procedure TSettings.FCreateSendtoShortcut;
var
IObject: IUnknown;
ISLink: IShellLink;
IPFile: IPersistFile;
TargetPath: string;
begin
{ Creates an instance of IShellLink }
IObject := CreateComObject(CLSID_ShellLink);
ISLink := IObject as IShellLink;
IPFile := IObject as IPersistFile;
TargetPath := ParamStr(0);
ISLink.SetPath(pChar(TargetPath));
ISLink.SetArguments(pChar(''));
ISLink.SetWorkingDirectory(pChar(ExtractFilePath(TargetPath)));
{ Create the link }
IPFile.Save(PWChar(FGetSendtoShortcutPath), false);
end;
function TSettings.FSendtoShortcutExists: Boolean;
begin
Result := FileExists(FGetSendtoShortcutPath);
end;
{$ENDIF}
procedure TSettings.FTranspModeWrite(Value: Integer);
begin
FIniFile.WriteInteger(sMain, 'TranspMode', Value);
end;
function TSettings.FTranspModeRead: Integer;
begin
Result := FIniFile.ReadInteger(sMain, 'TranspMode', 1);
end;
procedure TSettings.FStretchModeWrite(Value: Boolean);
begin
FIniFile.WriteBool(sMain, 'StretchMode', Value);
end;
function TSettings.FStretchModeRead: Boolean;
begin
Result := FIniFile.ReadBool(sMain, 'StretchMode', False);
end;
procedure TSettings.FLastDirWrite(const Value: string);
begin
FIniFile.WriteString(sMain, 'LastDir', UTF8ToSys(Value));
end;
function TSettings.FLastDirRead: string;
begin
Result := SysToUtf8(FIniFile.ReadString(sMain, 'LastDir', ''));
end;
procedure TSettings.FBackColorWrite(Color: TColor);
begin
FIniFile.WriteInteger(sMain, 'BackColor', Color);
end;
function TSettings.FBackColorRead: TColor;
begin
Result := FIniFile.ReadInteger(sMain, 'BackColor', clBtnFace);
end;
procedure TSettings.FBitModeWrite(Mode: Integer);
begin
FIniFile.WriteInteger(sMain, 'BitMode', Mode);
end;
function TSettings.FBitModeRead: Integer;
begin
Result := FIniFile.ReadInteger(sMain, 'BitMode', 0);
end;
procedure TSettings.FInfoVisibleWrite(Value: Boolean);
begin
FIniFile.WriteBool(sMain, 'InfoVisible', Value);
end;
function TSettings.FInfoVisibleRead: Boolean;
begin
Result := FIniFile.ReadBool(sMain, 'InfoVisible', True);
end;
constructor TSettings.Create(const DirPath: string);
begin
inherited Create;
FIniFile := TIniFile.Create(IncludeTrailingPathDelimiter(DirPath) + 'settings.t2v');
end;
destructor TSettings.Destroy;
begin
FIniFile.Free;
inherited Destroy;
end;
end.