first_run.icl 18.2 KB
Newer Older
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
module first_run

import StdEnv, StdMaybe, StdDebug
import registry, version
import UtilIO
import dodebug

//==

import code from library "errorkernel_library"

GetLastError :: Int
GetLastError = code {
	ccall GetLastError@4 "P:I"
	}

//==
	
Start w = startIO NDI Void pinit [ProcessClose closeProcess] w

pinit ps
	# ps = first_run app_vers app_path app_name ps
	= finish ps
where
	app_name = GetFileName long_path
	app_path = GetFilePath path
	app_vers = ReadVersionInfo
	path	 = winGetModulePath
	long_path= GetLongPathName path

GetFileName :: !String -> String;
GetFileName path
	| found	= (path % (inc position, dec (size path)));
			= path;
where 
	(found,position)	= LastColon path last;
	last				= dec (size path);
		
GetFilePath :: !String -> String;
GetFilePath path
	| found	= (path % (0, position));
			= path;
where 
	(found,position)	= LastColon path last;
	last				= dec (size path);
		
LastColon :: !String !Int -> (!Bool, !Int);
LastColon s i
	| i <= 0
		= (False,0);
	| dirseparator==s.[i]
	 	= (True, i);
		= LastColon s (dec i);

StripExtension :: !String -> String
StripExtension path
	| found	= (path % (0, dec position));
			= path;
where 
	(found,position)	= LastPeriod path last;
	last				= dec (size path);

LastPeriod :: !String !Int -> (!Bool, !Int);
LastPeriod s i
	| i <= 0
		= (False,0);
	| '.'==s.[i]
	 	= (True, i);
		= LastPeriod s (dec i);

finish :: !(PSt Void) -> PSt Void
finish ps
	# (_,ps) = openDialog Void (Dialog "Bye" NilLS [WindowClose (noLS closeProcess)]) ps
	#! ps = ps
	= ps

//==

ReadVersionInfo :: !String
ReadVersionInfo
	# t			= 7
	# dummy		= "abcd"
	# (r,t)		= GetFileVersionInfoSize path dummy t
	| r == 0
		= ""
//		= abort "GetFileVersionInfoSize failed...\n"
	# data		= createArray r '@'
	# (r,t)		= GetFileVersionInfo path 0 r data t
	| r == 0
		= ""
//		= abort ("GetFileVersionInfo failed...\n"+++toString GetLastError+++"\n")
	# buff		= "@@@@"
	# blen		= "@@@@"
	# (r,t)		= VerQueryValue data vers buff blen t
	| r == 0
		= ""
//		= abort "VerQueryValue failed...\n"
	| blen == zero
		= ""
//		= abort "No FileVersion info...\n"
	# sptr		= s2i buff
	# slen		= s2i blen
//	# info		= toString sptr +++ " :: " +++ toString slen
	# info		= {read_char p \\ p <- [sptr..] & x <- [1..slen]}
	= info
where
	path = winGetModulePath+++."\0"
	vers = "\\StringFileInfo\\040904B0\\FileVersion\0"
	zero = "\0\0\0\0"
	s2i s = (toInt s.[3] << 24) bitor (toInt s.[2] << 16) bitor (toInt s.[1] << 8) bitor (toInt s.[0])

//==

MyEntry		:== 1
NoEntry		:== 2
DiffEntry	:== 3

Yes			:== 1
No			:== 2
Never		:== 3

first_run app_vers app_path app_name ps
	# (run,ps)				= check_flag app_vers app_path app_name ps
	| not run
		= ps
	# (res,ps)				= check_registry app_path ps
	| res == MyEntry
		= ps
	| res == NoEntry
		# (res,ps)			= init_dialog ps
		| res == Yes
			# ps			= set_registry app_name app_path ps
			= ps
		| res == No
			= ps
		| res == Never
			# ps			= set_flag app_vers app_path app_name ps
			= ps
		= abort "Uncaught case in first_run:first_run: [2]\n"
	| res == DiffEntry
		# (res,ps)			= delta_dialog ps
		| res == Yes
			# ps			= set_registry app_name app_path ps
			= ps
		| res == No
			= ps
		| res == Never
			# ps			= set_flag app_vers app_path app_name ps
			= ps
		= abort "Uncaught case in first_run:first_run: [3]\n"
	= abort "Uncaught case in first_run:first_run: [1]\n"

uninstall application_path ps
	= abort "first_run:uninstall unimplemented.\n"
	
//==

check_flag app_vers app_path app_name ps
	// read flag => flag+vers+path+name
	// compare...
	// if vers & path & name match => use flag
	// otherwise run first-run
	# (ok,file,ps) = fopen "VERSION.txt" FReadText ps
	| not ok = abort "no VERSION"
	# (flag_vers,file)	= freadline file
	# (flag_name,file)	= freadline file
	# (flag_path,file)	= freadline file
	# flag_vers = dropnl flag_vers
	# flag_name = dropnl flag_name
	# flag_path = dropnl flag_path
	# (_,ps) = fclose file ps
	| app_vers == flag_vers && app_path == flag_path && app_name == flag_name
		= trace_n` "check=>False" (False,ps)
	= trace_n` "check=>True" (True,ps)
where
	flag_vers	= "2.0.1.42\0"
	flag_name	= "first_run.exe"
	flag_path	= "C:\\CLEANTOOLS\\REGISTRY\\"
	
	dropnl s = {c \\ c <-: s | c <> '\xA' && c <> '\xD'}

set_flag app_vers app_path app_name ps
	# ps = trace_n` ("set",app_vers,app_path,app_name) ps
	# (ok,file,ps) = fopen "VERSION.txt" FWriteText ps
	| not ok = abort "set failed"
	# file = writeln app_vers file
	# file = writeln app_name file
	# file = writeln app_path file
	# (_,ps) = fclose file ps
	= ps
where
	writeln s f = f <<< s <<< '\n'

check_registry app_path ps
	# (err,rs)			= ([],7)
	# (err,found,rs)	= check_file_type_in_registry registry_name command err rs
	| notEmpty err
		= abort (hd err +++. "\n")		///////////////!!!!!!!!!!!!!!!!!!!!!
	| found == ""
		= (NoEntry,ps)
	# mine				= quoted app_path
	| found <> mine
		= (DiffEntry,ps)
	= (MyEntry,ps)
where
	registry_name	= "iclfile\0"
	command			= "open\0"

	quoted string	= "\"" +++ string +++ "\" \"%1\""

set_registry app_name app_path ps
	# err		= change_ide_registry_fun app_name app_path
	# err		= change_pcl_registry_fun app_name app_path pcl_name pcl_path
	# err		= change_hcl_registry_fun app_name app_path hcl_name hcl_path
	| notEmpty err
		= abort (hd err +++. "\n")		///////////////!!!!!!!!!!!!!!!!!!!!!
	= ps

import StdIO

init_dialog :: !(PSt .l) -> (!Int,!PSt .l)
init_dialog ps
	# (okId,ps)			= openId ps
	# (cancelId,ps)		= openId ps
	# (dialogId,ps)		= openId ps
	# ((err,res),ps)	= openModalDialog No (idef okId cancelId dialogId) ps
	| err <> NoError || isNothing res
		= (No,ps)
	= (fromJust res,ps)
delta_dialog :: !(PSt .l) -> (!Int,!PSt .l)
delta_dialog ps
	# (okId,ps)			= openId ps
	# (cancelId,ps)		= openId ps
	# (dialogId,ps)		= openId ps
	# ((err,res),ps)	= openModalDialog No (ddef okId cancelId dialogId) ps
	| err <> NoError || isNothing res
		= (No,ps)
	= (fromJust res,ps)
idef okId cancelId dialogId = Dialog "Ide Integration"
	(	TextControl "The Clean Ide is currently not integrated" [ControlPos (Left,zero)]
	:+:	TextControl "into the Windows operating system." [ControlPos (Left,zero)]
	:+:	TextControl "Do this now?" [ControlPos (Left,zero)]
	:+:	ButtonControl "Never"
		[ ControlPos (Right,zero)
		, ControlFunction (dfun Never dialogId)
		]
	:+:	ButtonControl "No"	
		[ ControlPos (LeftOfPrev,zero)
		, ControlFunction (dfun No dialogId)
		, ControlId cancelId
		]
	:+: ButtonControl "Yes"	
		[ ControlPos (LeftOfPrev,zero)
		, ControlFunction (dfun Yes dialogId)
		, ControlId okId
		]
	)
	[ WindowId		dialogId
	, WindowOk		okId
	, WindowCancel	cancelId
	]
ddef okId cancelId dialogId = Dialog "Ide Integration"
	(	TextControl "A different Clean Ide is currently integrated" [ControlPos (Left,zero)]
	:+:	TextControl "into the Windows operating system." [ControlPos (Left,zero)]
	:+:	TextControl "Use this copy instead?" [ControlPos (Left,zero)]
	:+:	ButtonControl "Never"
		[ ControlPos (Right,zero)
		, ControlFunction (dfun Never dialogId)
		]
	:+:	ButtonControl "No"	
		[ ControlPos (LeftOfPrev,zero)
		, ControlFunction (dfun No dialogId)
		, ControlId cancelId
		]
	:+: ButtonControl "Yes"	
		[ ControlPos (LeftOfPrev,zero)
		, ControlFunction (dfun Yes dialogId)
		, ControlId okId
		]
	)
	[ WindowId		dialogId
	, WindowOk		okId
	, WindowCancel	cancelId
	]
dfun ret dId (_,ps)
	= (ret,closeWindow dId ps)
//==

Start`
	# (err,rs)			= ([],7)
	# (err,found,rs)	= check_file_type_in_registry registry_name command err rs
	| notEmpty err
		= hd err +++. "\n"
	# mine				= quoted winGetModulePath
	| found <> mine
		= "Different: " +++. found +++. " <=> " +++. mine +++. "\n"
	= "Same...\n"
	
where
	registry_name	= "iclfile\0"
	command			= "open\0"

	quoted string	= "\"" +++ string +++ "\" \"%1\""

//---

notEmpty [] = False
notEmpty _ = True

//---

import code from "cCrossCall_121.obj", "cCrossCallProcedureTable_121.obj", "cAcceleratorTable_121.obj", "cCrossCallCursor_121.obj",
				 "util_121.obj"
import code from library "userExt_library"

winGetModulePath ::  {#Char}
winGetModulePath
	= code
	{
		.inline WinGetModulePath
			ccall WinGetModulePath "-S"
		.end
	}

//---

:: RegistryKey	:== [String]

key_to_string [] = ""
key_to_string [k:ks] = "\\" +++ k % (0,size k-2) +++ key_to_string ks

//---

check_file_type_in_registry :: !String !String ![String] !RegistryState -> (![String],!String,!RegistryState)
check_file_type_in_registry registry_name command e rs
	# (e`,r,rs)	= check_registry_key key rs
	# e			= e++e`
	= (e,r,rs)
where
	key			= ["SOFTWARE\0","Classes\0",registry_name,"Shell\0",command,"command\0"]
	
check_registry_key :: !RegistryKey !RegistryState -> (![String],!String,!RegistryState)
check_registry_key key rs
	= check HKEY_LOCAL_MACHINE key True rs
where
	check :: !Int !RegistryKey !Bool !RegistryState -> (![String],!String,!RegistryState)
	check hkey [] is_a_string rs
		# data = createArray 256 '@'
		# size = "\0\1\0\0"
		# (r,rs) = if is_a_string
			(RegQueryValueEx hkey "\0" 0 0 data size rs)
			(RegQueryValueEx hkey "EditFlags\0" 0 0 data size rs)
		| r<>ERROR_SUCCESS
			= (["RegQueryValueEx failed\n"], "", rs)
//		# rs = trace_n ("data: "+++.data) rs
//		# rs = trace_n ("size: "+++. (convert size)) rs
		# size = convert2 size
		# value = data%(0,size-2)
		= ([],value,rs)
	check hkey [path:path_list] is_a_string rs
		#	(r,hkey2,rs) = RegOpenKeyEx hkey path 0 KEY_ALL_ACCESS rs
		| r<>ERROR_SUCCESS
			#	(r,hkey2,rs) = RegOpenKeyEx  hkey path 0 (KEY_READ bitor KEY_SET_VALUE) rs
			| r<>ERROR_SUCCESS
				= abort "RegOpenKeyEx failed\n" // 1
			# (e,r,rs) = check hkey2 path_list is_a_string rs
			# (_,rs) = RegCloseKey hkey2 rs
			= (e,r,rs)
		# (e,r,rs) = check hkey2 path_list is_a_string rs
		# (_,rs) = RegCloseKey hkey2 rs
		= (e,r,rs)

convert :: {#Char} -> String
convert s
	# l = [toString (toInt c) \\ c <-: s]
	= foldr (\l r -> l+++.";"+++.r) "" l

convert2 s
	# l = [toInt c \\ c <-: s]
	= foldr (\l r -> l + (r << 8)) 0 l

//==

:: DialogLS =
	{ icl :: !Bool
	, dcl :: !Bool
	, abc :: !Bool
	, prj :: !Bool
	, pcl :: !Bool
	, hcl :: !Bool
	}

remStart
	# (e,rs)	= ([],0)
	# (e,rs) = remove_file_type_from_registry ".icl\0" "iclfile\0" "open\0" e rs
	# (e,rs) = remove_file_type_from_registry ".dcl\0" "dclfile\0" "open\0" e rs
	# (e,rs) = remove_file_type_from_registry ".prj\0" "prjfile\0" "open\0" e rs
	# (e,rs) = remove_file_type_from_registry ".abc\0" "abcfile\0" "open\0" e rs
	# (e,rs) = remove_file_type_from_registry ".pcl\0" "pclfile\0" "open\0" e rs
	# (e,rs) = remove_file_type_from_registry ".hcl\0" "hclfile\0" "open\0" e rs
	= e

change_hcl_registry_fun ide_name ide_path hcl_name hcl_path
	# (e,rs)	= ([],0)
	# (e,rs)	= enter_file_type_in_registry hclMapping e rs
	= e
where
	hclMapping =
		{ fm_extension		= ".hcl\0"
		, fm_registry_name	= "hclfile\0"
		, fm_shell_name		= "Clean heap profile\0"
		, fm_command		= "open\0"
		, fm_use_dde		= True
		, fm_executable		= "\""+++hcl_path+++hcl_name+++"\" \"%1\"\0"
		, fm_application	= application
		, fm_icon			= (Just (ide_path+++ide_name+++",6\0"))
		}
	application	= StripExtension hcl_name +++. "\0"

change_pcl_registry_fun ide_name ide_path pcl_name pcl_path
	# (e,rs)	= ([],0)
	# (e,rs)	= enter_file_type_in_registry pclMapping e rs
	= e
where
	pclMapping =
		{ fm_extension		= ".pcl\0"
		, fm_registry_name	= "pclfile\0"
		, fm_shell_name		= "Clean time profile\0"
		, fm_command		= "open\0"
		, fm_use_dde		= True
		, fm_executable		= "\"" +++ pcl_path +++ pcl_name +++ "\" \"%1\"\0"
		, fm_application	= application
		, fm_icon			= (Just (ide_path+++ide_name+++",5\0"))
		}
	application	= StripExtension pcl_name +++. "\0"

change_ide_registry_fun name path
	# (e,rs)	= ([],0)
	# (e,rs)	= enter_file_type_in_registry iclMapping e rs
	# (e,rs)	= enter_file_type_in_registry dclMapping e rs
	# (e,rs)	= enter_file_type_in_registry prjMapping e rs
	# (e,rs)	= enter_file_type_in_registry abcMapping e rs
	= e
where
	abcMapping =
		{ fm_extension		= ".abc\0"
		, fm_registry_name	= "abcfile\0"
		, fm_shell_name		= "Clean ABC file\0"
		, fm_command		= "open\0"
		, fm_use_dde		= True
		, fm_executable		= "\"" +++ path +++ name +++ "\" \"%1\"\0"
		, fm_application	= application
		, fm_icon			= (Just (path+++name+++",2\0"))
		}
	prjMapping =
		{ fm_extension		= ".prj\0"
		, fm_registry_name	= "prjfile\0"
		, fm_shell_name		= "Clean project file\0"
		, fm_command		= "open\0"
		, fm_use_dde		= True
		, fm_executable		= "\"" +++ path +++ name +++ "\" \"%1\"\0"
		, fm_application	= application
		, fm_icon			= (Just (path+++name+++",1\0"))
		}
	iclMapping =
		{ fm_extension		= ".icl\0"
		, fm_registry_name	= "iclfile\0"
		, fm_shell_name		= "Clean implementation module\0"
		, fm_command		= "open\0"
		, fm_use_dde		= True
		, fm_executable		= "\"" +++ path +++ name +++"\" \"%1\"\0"
		, fm_application	= application
		, fm_icon			= (Just (path+++name+++",4\0"))
		}
	dclMapping =
		{ fm_extension		= ".dcl\0"
		, fm_registry_name	= "dclfile\0"
		, fm_shell_name		= "Clean definition module\0"
		, fm_command		= "open\0"
		, fm_use_dde		= True
		, fm_executable		= "\"" +++ path +++ name +++ "\" \"%1\"\0"
		, fm_application	= application
		, fm_icon			= (Just (path+++name+++",3\0"))
		}
	application	= StripExtension name +++. "\0"

//==

:: FileMapping =
	{ fm_extension		:: !String			// the extension being mapped							[NULL-terminated]
	, fm_registry_name	:: !String			// the filetype name used internally in the registry	[NULL-terminated]
	, fm_shell_name		:: !String			// the filetype description visible to Windows users	[NULL-terminated]
	, fm_command		:: !String			// the command being mapped								[NULL-terminated]
	, fm_use_dde		:: !Bool			// ...
	, fm_executable		:: !String			// quoted path to executable plus arguments				[NULL-terminated]
	, fm_application	:: !String			// application name										[NULL-terminated]
	, fm_icon			:: !Maybe !String	// resource identifier string							[NULL-terminated]
	}
	
enter_file_type_in_registry :: !FileMapping [String] !RegistryState -> (![String],!RegistryState)
enter_file_type_in_registry fm e rs
	# (e,rs) = add_to_registry p1 fm.fm_registry_name True e rs
	# (e,rs) = add_to_registry p2 fm.fm_shell_name True e rs
	# (e,rs) = add_to_registry p3 "\0" True e rs
	# (e,rs) = add_to_registry p4 "\x1\0\0\0" False e rs
	# (e,rs) = add_to_registry p5 fm.fm_executable True e rs
	| not fm.fm_use_dde
		= (e,rs)
	# (e,rs) = add_to_registry p6 "%1\0" True e rs
	# (e,rs) = add_to_registry p7 "CLEANOPEN\0" True e rs
	# (e,rs) = add_to_registry p8 fm.fm_application True e rs
	| isNothing fm.fm_icon
		= (e,rs)
	# (e,rs) = add_to_registry p9 (fromJust fm.fm_icon) True e rs
	= (e,rs)
where
	p1 = ["SOFTWARE\0","Classes\0",fm.fm_extension]
	p2 = ["SOFTWARE\0","Classes\0",fm.fm_registry_name]
	p3 = ["SOFTWARE\0","Classes\0",fm.fm_registry_name,"Shell\0"]
	p4 = ["SOFTWARE\0","Classes\0",fm.fm_registry_name,"Shell\0",fm.fm_command]
	p5 = ["SOFTWARE\0","Classes\0",fm.fm_registry_name,"Shell\0",fm.fm_command,"command\0"]
	p6 = ["SOFTWARE\0","Classes\0",fm.fm_registry_name,"Shell\0",fm.fm_command,"ddeexec\0"]
	p7 = ["SOFTWARE\0","Classes\0",fm.fm_registry_name,"Shell\0",fm.fm_command,"ddeexec\0","topic\0"]
	p8 = ["SOFTWARE\0","Classes\0",fm.fm_registry_name,"Shell\0",fm.fm_command,"ddeexec\0","Application\0"]
	p9 = ["SOFTWARE\0","Classes\0",fm.fm_registry_name,"DefaultIcon\0"]

remove_file_type_from_registry :: !String !String !String ![String] !RegistryState -> (![String],!RegistryState)
remove_file_type_from_registry extension registry_name command e rs
	# (e,rs)=remove_from_registry p1 e rs
	# (e,rs)=remove_from_registry p2 e rs
	# (e,rs)=remove_from_registry p3 e rs
	# (e,rs)=remove_from_registry p4 e rs
	# (e,rs)=remove_from_registry p5 e rs
	# (e,rs)=remove_from_registry p6 e rs
	# (e,rs)=remove_from_registry p7 e rs
	# (e,rs)=remove_from_registry p8 e rs
	# (e,rs)=remove_from_registry p9 e rs
	= (e,rs)
where
	p1 = ["SOFTWARE\0","Classes\0",registry_name,"Shell\0",command,"ddeexec\0","topic\0"]
	p2 = ["SOFTWARE\0","Classes\0",registry_name,"Shell\0",command,"ddeexec\0","Application\0"]
	p3 = ["SOFTWARE\0","Classes\0",registry_name,"Shell\0",command,"ddeexec\0"]
	p4 = ["SOFTWARE\0","Classes\0",registry_name,"Shell\0",command,"command\0"]
	p5 = ["SOFTWARE\0","Classes\0",registry_name,"Shell\0",command]
	p6 = ["SOFTWARE\0","Classes\0",registry_name,"Shell\0"]
	p7 = ["SOFTWARE\0","Classes\0",registry_name,"DefaultIcon\0"]
	p8 = ["SOFTWARE\0","Classes\0",registry_name]
	p9 = ["SOFTWARE\0","Classes\0",extension]

//==

add_to_registry :: [String] String Bool [String] RegistryState -> (![String],!RegistryState)
add_to_registry path value is_a_string e rs
	# (r,rs)	= add_to_registry` HKEY_LOCAL_MACHINE path value is_a_string rs
	# e = if (r<>0) (key_add_error path e) e
	= (e,rs)
where
	key_add_error :: [String] [String] -> [String]
	key_add_error p e = e++["Adding '" +++ key_to_string p+++"' failed\n"]

remove_from_registry :: [String] [String] RegistryState -> (![String],!RegistryState)
remove_from_registry path e rs
	# (r,rs)	= remove_from_registry` HKEY_LOCAL_MACHINE path rs
	# e			= if (r<>0) (key_rem_error path e) e
	= (e,rs)
where
	key_rem_error :: [String] [String] -> [String]
	key_rem_error p e = e++["Removing '" +++ key_to_string p+++"' failed\n"]

//==

add_to_registry` :: Int [String] String Bool RegistryState -> (!Int,!RegistryState)
add_to_registry` hkey1 [] value value_is_a_string rs
	# (r,rs) = if value_is_a_string
			(RegSetValueEx hkey1 "\0" 0 REG_SZ value (size value) rs)
			(RegSetValueEx hkey1 "EditFlags\0" 0 REG_BINARY value 4 rs)
	| r<>ERROR_SUCCESS
		= abort "RegSetValueEx failed\n" // 1
		= (0,rs)
add_to_registry` hkey1 [path:path_list] value value_is_a_string rs
	#	(r,hkey2,dw,rs) = RegCreateKeyEx hkey1 path 0 "\0" REG_OPTION_NON_VOLATILE KEY_ALL_ACCESS 0 rs
	| r<>ERROR_SUCCESS
		#	(r,hkey2,dw,rs) = RegCreateKeyEx  hkey1 path 0 "\0" REG_OPTION_NON_VOLATILE (KEY_READ bitor KEY_SET_VALUE) 0 rs
		| r<>ERROR_SUCCESS
			= abort "RegCreateKeyEx failed\n" // 1
		# (r,rs) = add_to_registry` hkey2 path_list value value_is_a_string rs
		# (_,rs) = RegCloseKey hkey2 rs
		= (r,rs)
	# (r,rs) = add_to_registry` hkey2 path_list value value_is_a_string rs
	# (_,rs) = RegCloseKey hkey2 rs
	= (r,rs)

remove_from_registry` :: Int [String] RegistryState -> (!Int,!RegistryState)
remove_from_registry` hkey [path] rs
	# (r,rs) =RegDeleteKey hkey path rs
	| r==ERROR_SUCCESS
		= (0,rs)
		= (1,rs)
remove_from_registry` hkey [path:path_list] rs
	# (r,hkey2,rs) = RegOpenKeyEx hkey path 0 (KEY_READ bitor KEY_SET_VALUE) rs
	| r<>ERROR_SUCCESS
			= (1,rs)
	# (r,rs)=remove_from_registry` hkey2 path_list rs
	| r==r
		# (rc,rs) = RegCloseKey hkey2 rs
		| rc==rc
			= (r,rs)
			= (r,rs)