-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfcustomenvhelper.prg
364 lines (256 loc) · 8.72 KB
/
nfcustomenvhelper.prg
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
*----------------------------------------------------------------------------
* Creates a custom startup environment for desired project folder
* a shortcut in selected folder.
* Marco Plaza, 2024
* v.1.2.7 https://github.com/nfoxdev/nfCustomEnvHelper
*-----------------------------------------------------------------------------
private all
#define envfolder '_customEnv'
#define wcap 'nfCustomEnvHelper'
#define crlf chr(13)+chr(10)
set safety off
set talk off
set notify off
try
workdir = getdir('','Folder to create the shortcut and custom environment:','nfCustomEnvHelper',16+32+64)
if !directory(m.workdir)
error 'No directory selected!'
endif
*-- check & create vfpenv folder in destfolder
custfilesdir = m.workdir + envfolder
if !directory(m.custfilesdir)
mkdir (m.custfilesdir)
endif
*-- check for _resource.dbf in dest folder:
curresource = sys(2005)
custresource = forcepath('resource.dbf',m.custfilesdir)
*-- SELECT CLONE / NEW ENV:
if atc(m.curresource,m.custresource) > 0
lreset = qu('Reset current custom resource?')
lproceed = m.lreset
lclone = .f.
else
lproceed = !file(m.custresource) or qu('Destination already has a resource file! '+crlf+' overwrite?')
lclone = file(m.curresource) and m.lproceed and qu('Clone current resource? No = creates a new one')
endif
*-- create resource:
set resource off
if m.lproceed
if m.lclone
select * from (m.curresource) into table (m.custresource)
use
use in (select(juststem(m.curresource)))
messagebox('Current Resource cloned',0,wcap)
else
create table (m.custresource) ( type c(12),id c(12),name m(4),readonly l(1),ckval n(6,0),data m(4),updated d(8))
use
messagebox('New Resource created',0,wcap)
endif
endif
set resource on
*-- config.fpw in dest folder:
custconfig= forcepath('config.fpw',m.custfilesdir)
curconfig = sys(2019)
if atc(m.custconfig,m.curconfig) = 0
if file(m.curconfig)
copy file (m.curconfig) to (m.custconfig)
else
strtofile('',m.custconfig)
endif
endif
*-- pick a custom backcolor:
custbackcolor = 0
messagebox('Pick a Custom Screeen BackColor...',0,wcap)
custbackcolor = getcolor(_screen.backcolor)
custbackcolor = iif(m.custbackcolor>0,m.custbackcolor,rgb(255,255,255))
*-- create afterstartup.prg in customconfig folder as sample
custstartup = forcepath('startup.prg',m.custfilesdir)
custafterstartup = forcepath('afterStartup.prg',m.custfilesdir)
createstartup(m.workdir,m.custstartup,m.custconfig,m.custbackcolor,custafterstartup)
*-- set resource and call startup.prg in config.fpw
writekey(m.custconfig,'resource',m.custresource)
writekey(m.custconfig,'default',m.workdir)
writekey(m.custconfig,'command',textmerge('do "<<m.custStartup>>"'))
*-- select icon
selectedicon = ''
* try use folder custom icon:
try
selectedicon = strextract(filetostr(forcepath('desktop.ini',m.workdir)),'IconResource=',',')
if !file(m.selectedicon)
error 'no icon'
endif
catch
qu('Folder has no custom icon.. Select one for this shortcut',0)
endtry
if !file(m.selectedicon) or !qu('Use Icon '+m.selectedicon+'?',4)
selectedicon = getfile('Select an ico, exe or dll file to set icon for this shortcut:ico,exe,dll','Icon.:','Select',0,'Select a custom icon for this shortcut')
if !file(m.selectedicon)
qu('No icon selected.. using vfp icon',0)
selectedicon = _vfp.servername
endif
endif
*-- when icon file selected is an ico , force windows to upate miniatures using a copy:
if lower(justext(m.selectedicon)) == 'ico'
iconcopy = forcepath('favicon'+sys(2015)+'.ico',m.custfilesdir)
copy file (m.selectedicon) to (m.iconcopy)
selectedicon = m.iconcopy
endif
*-- select shortcut folder/name:
oshell = createobject('wscript.shell')
defaultshortcut = forcepath(;
'VFP9 @ '+proper(chrtran(m.workdir,'\:',' ')),;
oshell.specialfolders.item('desktop');
)
do while .t.
shname = putfile('Save shortcut as: ',m.defaultshortcut,'lnk')
do case
case !empty(m.shname)
exit
case qu(' No valid shortcut selected - Cancel procedure?',4)
error 'No shortcut file name selected!'
endcase
enddo
shname = forceext(rtrim(evl(m.shname,m.defaultshortcut)),'lnk')
*-- ...create shortcut
with m.oshell.createshortcut( m.shname )
.targetpath = '"'+_vfp.servername+'"'
.workingdirectory = m.workdir
.arguments = [-c"]+m.custconfig+["]
.description = 'created using nfCustomEnvHelper'
.windowstyle = 1
.iconlocation = m.selectedIcon
.save()
endwith
*-- save also in custom config folder:
copy file (m.shname) to (forcepath(m.shname,m.custfilesdir))
*-- open?:
if qu('Shortcut saved as '+m.shname+'! open? ',4)
!start "" "&shname"
endif
catch to err when err.errorno = 1098
messagebox(err.message,0,wcap)
catch to err
messagebox(textmerge('oops.. <<CHR(13)>>error number:<<err.errorno>> at:<<err.lineno>> <<CHR(13)>> <<err.message>>'),48,wcap)
endtry
*--------------------------------------------
function qu(cm,diagtype)
*--------------------------------------------
local ures
diagtype = evl(m.diagtype,3)
ures = messagebox(m.cm,m.diagtype+iif(m.diagtype=4,0,256),wcap)
if m.ures = 2
error 'Helper canceled'
else
return ures = 6
endif
*---------------------------------
function getforecolor(tncolor)
*---------------------------------
local r,g,b,luma
r = bitand(m.tncolor, 0xff)
g = bitand(bitrshift(m.tncolor, 8), 0xff)
b = bitand(bitrshift(m.tncolor, 16), 0xff)
luma = ((0.299 * m.r) + (0.587 * m.g) + (0.114 * m.b)) / 255
return iif(m.luma > 0.7, rgb(0,0,0), rgb(255,255,255))
*---------------------------------
function getkey(m.csrc,key)
*---------------------------------
local value
local nel
local array aa(1)
value = ''
try
alines(aa,filetostr(m.csrc))
nel=ascan(aa,m.key)
if upper( getwordnum(aa(m.nel),1,'=')) == upper(m.key)
value = getwordnum(aa(m.nel),2,'=')
endif
catch
endtry
return m.value
*-------------------------------------
function writekey(m.csrc,key,value)
*-------------------------------------
local nkv,addk,line,aa(1)
if vartype(m.key) # 'C' or vartype(m.value) # 'C'
error 'key value not a character expression'
endif
nkv = m.key+'='+m.value+crlf
alines(aa,filetostr(m.csrc))
addk = .t.
strtofile('',m.csrc)
for each line in aa
if atc(m.key,getwordnum(m.line,1,'='))>0
strtofile(m.nkv,m.csrc,1)
addk = .f.
else
strtofile(m.line+crlf,m.csrc,1)
endif
endfor
if m.addk
strtofile(m.nkv,m.csrc,1)
endif
*---------------------------------------------------------------------------------------
procedure createstartup(workdir,custstartup,custconfig,custbackcolor,afterstartup)
*---------------------------------------------------------------------------------------
local projfile,thisprg,temp
*-- create startup.prg
thisprg = forceext(getwordnum(sys(16),3),'prg')
text to temp noshow textmerge
*-------------------------------------------------------
* Custom startup generated by nfCustomEnvHelper.prg
* https://github.com/nfoxdev/nfCustomEnvHelper
*-------------------------------------------------------
define pad _devpad of _msysmenu prompt 'Custom Env.'
define popup _devpop
define bar 1 of _devpop prompt ' Create a Custom Startup'
define bar 2 of _devpop prompt ' do "<<JUSTFNAME(m.custStartup)>>"' key F5,'F5'
define bar 3 of _devpop prompt '\-'
define bar 4 of _devpop prompt ' edit "<<JUSTFNAME(m.custConfig)>>"'
define bar 5 of _devpop prompt ' edit "<<JUSTFNAME(m.custStartup)>>"'
define bar 6 of _devpop prompt ' edit "<<JUSTFNAME(m.custAfterStartup)>>"'
on pad _devpad of _msysmenu activate popup _devpop
on selection bar 1 of _devpop do "<<m.thisprg>>"
on selection bar 2 of _devpop do "<<m.custStartup>>"
on selection bar 4 of _devpop editsource("<<m.custConfig>>")
on selection bar 5 of _devpop editsource("<<m.custStartup>>")
on selection bar 6 of _devpop editsource("<<m.custAfterStartup>>")
set status bar on
set memowidth to 100
cd "<<m.workdir>>"
with _screen
.visible = .t.
.caption = fullpath('')
.forecolor = <<getforecolor(m.custbackcolor)>>
.backcolor = <<m.custbackcolor>>
.fontname = 'Ebrima'
.fontsize = 12
clear
@ 2,5 say fullpath('') font 'foxfont',26
? ' '
? 'Search Path: '
? '-'+strtran(set('path'),';',' -')
? 'dir *.*:'
dir *.*
endwith
if file("<<m.afterStartup>>")
do "<<m.afterStartup>>"
endif
set sysmenu save
ENDTEXT
*-- save startup.prg:
strtofile(m.temp,m.custstartup)
*-- create afterStartup.prg if not present:
if !file(m.afterstartup)
text to temp noshow textmerge
*-------------------------------------------------------
* Custom startup generated by nfCustomEnvHelper.prg
* https://github.com/nfoxdev/nfCustomEnvHelper
*-------------------------------------------------------
* place here code to run after startup for this project
*
*
do <<forcepath("nfCustomEnvHelperUtils.prg",justpath(m.thisprg))>>
ENDTEXT
strtofile(m.temp,m.afterstartup)
endif