Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2292 leency 1
format PE GUI 4.0 at 400000h
2
section '.text' code readable executable
3
entry start
4
 
5
include 'config_resource.inc'
6
 
7
start:
8
        call    [GetProcessHeap]
9
        mov     [hHeap], eax
10
        xor     ebx, ebx
11
; SHBrowseForFolder requires CoInitialize (according to docs)
12
        push    2
13
        push    ebx
14
        call    [CoInitializeEx]
15
        mov     edi, full_ini_name
16
        push    1000
17
        push    edi
18
        push    ebx
19
        call    [GetModuleFileNameA]
20
@@:
21
        inc     edi
22
        cmp     byte [edi-1], 0
23
        jnz     @b
24
@@:
25
        dec     edi
26
        cmp     byte [edi-1], '\'
27
        jnz     @b
28
        mov	[pathzeroptr], edi
29
        mov     esi, IniFileName
30
@@:
31
        lodsb
32
        stosb
33
        test    al, al
34
        jnz     @b
35
        push    ebx             ; hTemplateFile
36
        push    80h             ; dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL
37
        push    1               ; dwCreationDisposition = CREATE_NEW
38
        push    ebx             ; lpSecurityAttributes
39
        push    ebx             ; dwShareMode
40
        push    40000000h       ; dwDesiredAccess = GENERIC_WRITE
41
        push    full_ini_name   ; lpFileName
42
        call    [CreateFileA]
43
        mov     esi, eax
44
        inc     eax
45
        jz      .ini_exists
46
        push    eax
47
        mov     eax, esp
48
        push    ebx             ; lpOverlapped
49
        push    eax             ; lpNumberOfBytesWritten
50
        push    ini_size        ; nNumberOfBytesToWrite
51
        push    ini             ; lpBuffer
52
        push    esi             ; hFile
53
        call    [WriteFile]
54
        pop     eax
55
        push    esi
56
        call    [CloseHandle]
57
.ini_exists:
58
        push    ebx
59
        push    DlgProc
60
        push    ebx
61
        push    IDD_DIALOG1
62
        push    400000h
63
        call    [DialogBoxParamA]
64
        push    eax
65
        call    [CoUninitialize]
66
        call    [ExitProcess]
67
 
68
DlgProc:
69
        push    ebx
70
        mov     ebx, [esp+8]
71
        mov     eax, [esp+12]
72
        cmp     eax, 10h        ; WM_CLOSE
73
        jz      .close
74
        sub     eax, 110h       ; WM_INITDIALOG
75
        jz      .init
76
        dec     eax             ; WM_COMMAND
77
        jz      .command
78
        pop     ebx
79
        xor     eax, eax
80
        ret     16
81
.close:
82
        push    0
83
        push    ebx
84
        call    [EndDialog]
85
.true:
86
        pop     ebx
87
        xor     eax, eax
88
        inc     eax
89
        ret     16
90
.command:
91
        cmp     word [esp+16], 2        ; IDCANCEL
92
        jz      .close
93
        cmp     word [esp+16], IDC_HD_DEV
94
        jnz     .no_hd_dev
95
        cmp     word [esp+18], 1        ; LBN_SELCHANGE
96
        jnz     .true
97
.lastdel:
98
        call    OnSelectHdDev
99
        jmp     .true
100
.no_hd_dev:
101
        cmp     word [esp+16], IDC_HD_PART
102
        jnz     .no_hd_part
103
        cmp     word [esp+18], 1
104
        jnz     .true
105
        cmp     [cur_hd_dev], -1
106
        jz      .true
107
        call    OnSelectHdPart
108
        jmp     .true
109
.no_hd_part:
110
        mov     eax, IDC_SKIN
111
        mov     [filter], skn_filter
112
        cmp     word [esp+16], IDC_SKIN_BROWSE
113
        jz      @f
114
        mov     eax, IDC_FONT1
115
        mov     [filter], mt_filter
116
        cmp     word [esp+16], IDC_FONT1_BROWSE
117
        jz      @f
118
        mov     eax, IDC_FONT2
119
        cmp     word [esp+16], IDC_FONT2_BROWSE
120
        jnz     .nofilebrowse
121
@@:
122
        push    eax
123
        push    512
124
        push    cur_ini_param
125
        push    eax
126
        push    ebx
127
        call    [GetDlgItemTextA]
128
        push    ofn
129
        call    [GetOpenFileNameA]
130
        test    eax, eax
131
        pop     eax
132
        jz      .true
133
        push    cur_ini_param
134
        push    eax
135
        push    ebx
136
        call    [SetDlgItemTextA]
137
        jmp     .true
138
.nofilebrowse:
139
        mov     eax, IDC_RAMDISK
140
        cmp     word [esp+16], IDC_RAMDISK_BROWSE
141
        jz      @f
142
        mov     eax, IDC_PARTITION
143
        cmp     word [esp+16], IDC_PARTITION_BROWSE
144
        jnz     .nodirbrowse
145
@@:
146
        push    eax
147
        push    512
148
        push    cur_ini_param
149
        push    eax
150
        push    ebx
151
        call    [GetDlgItemTextA]
152
        push    bi
153
        call    [SHBrowseForFolder]
154
        test    eax, eax
155
        pop     ecx
156
        jz      .true
157
        push    ecx eax
158
        push    cur_ini_param
159
        push    eax
160
        call    [SHGetPathFromIDList]
161
        test    eax, eax
162
        pop     eax ecx
163
        jz      .nodir
164
        push    eax
165
        push    cur_ini_param
166
        push    ecx
167
        push    ebx
168
        call    [SetDlgItemTextA]
169
        pop     eax
170
.nodir:
171
        push    eax
172
        push    eax
173
        push    esp
174
        call    [SHGetMalloc]
175
        pop     eax
176
        pop     edx
177
        push    eax
178
        push    edx
179
        push    eax
180
        mov     eax, [eax]
181
        call    dword [eax+20]
182
        pop     eax
183
        push    eax
184
        mov     eax, [eax]
185
        call    dword [eax+8]
186
        jmp     .true
187
.nodirbrowse:
188
        cmp     word [esp+16], IDC_ADD_PARTITION
189
        jnz     .noadd
190
        cmp     [cur_hd_dev], -1
191
        jz      .true
192
        push    eax
193
        call    set_cur_part
194
        pop     eax
195
        mov     eax, [cur_hd_dev]
196
        mov     ecx, [hdns+eax*4]
197
        inc     cl
198
        jnz     @f
199
        push    10h
200
        push    0
201
        push    aTooManyPartitions
202
        push    ebx
203
        call    [MessageBoxA]
204
        jmp     .true
205
@@:
206
        mov     [hdns+eax*4], ecx
207
        push    eax
208
        shl     ecx, 9
209
        mov     edx, [hdpart+eax*4]
210
        test    edx, edx
211
        jz      .alloc
212
        push    ecx
213
        push    [hdpart+eax*4]
214
        push    0
215
        push    [hHeap]
216
        call    [HeapReAlloc]
217
        jmp     @f
218
.alloc:
219
        push    ecx
220
        push    0
221
        push    [hHeap]
222
        call    [HeapAlloc]
223
@@:
224
        pop     ecx
225
        mov     [hdpart+ecx*4], eax
226
        call    OnSelectHdDev
227
        mov     eax, [cur_hd_dev]
228
        mov     ecx, [hdns+eax*4]
229
        dec     ecx
230
        mov     eax, [hdpart+eax*4]
231
        push    0
232
        push    ecx
233
        shl     ecx, 9
234
        mov     byte [eax+ecx], 0
235
        mov     byte [eax+ecx+511], 0
236
        push    186h            ; LB_SETCURSEL
237
        push    IDC_HD_PART
238
        push    ebx
239
        call    [SendDlgItemMessageA]
240
        call    OnSelectHdPart
241
        jmp     .true
242
.noadd:
243
        cmp     word [esp+16], IDC_DEL_PARTITION
244
        jnz     .nodel
245
        mov     eax, [cur_hd_dev]
246
        cmp     eax, -1
247
        jz      .true
248
        mov     ecx, [hdns+eax*4]
249
        dec     ecx
250
        js      .true
251
        mov     [hdns+eax*4], ecx
252
        push    eax ecx
253
        push    0
254
        push    ecx
255
        push    182h            ; LB_DELETESTRING
256
        push    IDC_HD_PART
257
        push    ebx
258
        call    [SendDlgItemMessageA]
259
        pop     ecx eax
260
        push    eax
261
        shl     ecx, 9
262
        push    ecx
263
        push    [hdpart+eax*4]
264
        push    0
265
        push    [hHeap]
266
        call    [HeapReAlloc]
267
        pop     ecx
268
        mov     [hdpart+ecx*4], eax
269
        mov     eax, [hdns+ecx*4]
270
        test    eax, eax
271
        jz      .lastdel
272
        cmp     [cur_hd_part], eax
273
        jnz     @f
274
        or      [cur_hd_part], -1
275
        push    0
276
        push    eax
277
        push    186h
278
        push    IDC_HD_PART
279
        push    ebx
280
        call    [SendDlgItemMessageA]
281
@@:
282
        call    OnSelectHdPart
283
        jmp     .true
284
.nodel:
285
        cmp     word [esp+16], IDC_NOTEMPTY_EXT
286
        jnz     .noassoc
287
        push    0
288
        push    0
289
        push    0F0h            ; BM_GETCHECK
290
        push    IDC_NOTEMPTY_EXT
291
        push    ebx
292
        call    [SendDlgItemMessageA]
293
        push    eax
294
        mov     ecx, IDC_EXTENSIONS
295
        call    enable_part_items.1
296
        pop     eax
297
        jmp     .true
298
.noassoc:
299
        cmp     word [esp+16], 1        ; IDOK
300
        jnz     .true
301
        call    set_cur_part
302
; check input parameters
303
	push	esi
304
	mov	esi, [pathzeroptr]
305
	mov	byte [esi-1], 0
306
	push	full_ini_name
307
	call	[SetCurrentDirectoryA]
308
	mov	byte [esi-1], '\'
309
	pop	esi
310
        mov     ecx, IDC_RAMDISK
311
        call    check_file_exists
312
        mov     ecx, IDC_SKIN
313
        call    check_file_exists
314
        mov     ecx, IDC_FONT1
315
        call    check_file_exists
316
        mov     ecx, IDC_FONT2
317
        call    check_file_exists
318
; ramdisk
319
        push    512
320
        push    cur_ini_param
321
        push    IDC_RAMDISK
322
        push    ebx
323
        call    [GetDlgItemTextA]
324
        mov     ecx, cur_ini_param
325
        call    add_trailing_slash
326
        push    full_ini_name
327
        push    cur_ini_param
328
        push    ramdisk_keyname
329
        push    aDisk
330
        call    [WritePrivateProfileStringA]
331
; hard disks - delete old values
332
        push    esi
333
        xor     esi, esi
334
        mov     [aHdNn+2], '0'
335
.readhd_del:
336
        push    full_ini_name   ; lpFileName
337
        push    0               ; nDefault
338
        push    aHdNn           ; lpKeyName
339
        push    aDisk           ; lpAppName
340
        call    [GetPrivateProfileIntA]
341
        push    eax
342
        push    full_ini_name
343
        push    0
344
        push    aHdNn
345
        push    aDisk
346
        call    [WritePrivateProfileStringA]
347
        pop     eax
348
        inc     [aHdNn+2]
349
        test    eax, eax
350
        jz      .3
351
        push    eax
352
        push    1
353
.2:
354
        push    dword [esp]
355
        push    esi
356
        push    aHdNM
357
        push    cur_ini_name
358
        call    [wsprintfA]
359
        add     esp, 10h
360
        push    full_ini_name
361
        push    0
362
        push    cur_ini_name
363
        push    aDisk
364
        call    [WritePrivateProfileStringA]
365
        pop     ecx
366
        inc     ecx
367
        cmp     ecx, [esp]
368
        ja      @f
369
        push    ecx
370
        jmp     .2
371
@@:
372
        pop     eax
373
.3:
374
        inc     esi
375
        cmp     esi, 4
376
        jb      .readhd_del
377
; hard disks - write new values
378
        xor     esi, esi
379
        mov     [aHdNn+2], '0'
380
.writehd:
381
        mov     eax, [hdns+esi*4]
382
        test    eax, eax
383
        jz      .writehd_next
384
        push    edi
385
        push    -'0'
386
@@:
387
        xor     edx, edx
388
        mov     ecx, 10
389
        div     ecx
390
        push    edx
391
        test    eax, eax
392
        jnz     @b
393
@@:
394
        mov     edi, cur_ini_param
395
@@:
396
        pop     eax
397
        add     al, '0'
398
        stosb
399
        jnz     @b
400
        pop     edi
401
        push    full_ini_name
402
        push    cur_ini_param
403
        push    aHdNn
404
        push    aDisk
405
        call    [WritePrivateProfileStringA]
406
        push    1
407
.4:
408
        push    dword [esp]
409
        push    esi
410
        push    aHdNM
411
        push    cur_ini_name
412
        call    [wsprintfA]
413
        add     esp, 10h
414
        pop     eax
415
        push    eax
416
        dec     eax
417
        shl     eax, 9
418
        push    esi edi
419
        mov     esi, [hdpart+esi*4]
420
        add     esi, eax
421
        mov     edi, cur_ini_param
422
        push    esi
423
@@:
424
        lodsb
425
        stosb
426
        test    al, al
427
        jnz     @b
428
        pop     esi
429
        cmp     byte [esi+511], 0
430
        jz      @f
431
        mov     byte [edi-1], ','
432
        mov     dword [edi], 'read'
433
        mov     dword [edi+4], 'only'
434
        mov     byte [edi+8], 0
435
@@:
436
        pop     edi esi
437
        push    full_ini_name
438
        push    cur_ini_param
439
        push    cur_ini_name
440
        push    aDisk
441
        call    [WritePrivateProfileStringA]
442
        pop     ecx
443
        inc     ecx
444
        cmp     ecx, [hdns+esi*4]
445
        ja      .writehd_next
446
        push    ecx
447
        jmp     .4
448
.writehd_next:
449
        inc     [aHdNn+2]
450
        inc     esi
451
        cmp     esi, 4
452
        jb      .writehd
453
; skin file
454
        push    512
455
        push    cur_ini_param
456
        push    IDC_SKIN
457
        push    ebx
458
        call    [GetDlgItemTextA]
459
        push    full_ini_name
460
        push    cur_ini_param
461
        push    aSkin
462
        push    aMain
463
        call    [WritePrivateProfileStringA]
464
; system fonts
465
        push    512
466
        push    cur_ini_param
467
        push    IDC_FONT1
468
        push    ebx
469
        call    [GetDlgItemTextA]
470
        push    full_ini_name
471
        push    cur_ini_param
472
        push    aFont1
473
        push    aMain
474
        call    [WritePrivateProfileStringA]
475
        push    512
476
        push    cur_ini_param
477
        push    IDC_FONT2
478
        push    ebx
479
        call    [GetDlgItemTextA]
480
        push    full_ini_name
481
        push    cur_ini_param
482
        push    aFont2
483
        push    aMain
484
        call    [WritePrivateProfileStringA]
485
; associations
486
        push    0
487
        push    0
488
        push    0F0h
489
        push    IDC_EMPTY_EXT
490
        push    ebx
491
        call    [SendDlgItemMessageA]
492
        cmp     eax, [bWasEmptyAssoc]
493
        jz      .nomodify_empty_assoc
494
        test    eax, eax
495
        jz      .del_empty_assoc
496
        mov     esi, null
497
        call    add_assoc
498
        jmp     .nomodify_empty_assoc
499
.del_empty_assoc:
500
        mov     esi, null
501
        call    del_assoc
502
.nomodify_empty_assoc:
503
        push    edi
504
        mov     esi, cur_ext
505
        mov     byte [esi], 0
506
        push    0
507
        push    0
508
        push    0F0h
509
        push    IDC_NOTEMPTY_EXT
510
        push    ebx
511
        call    [SendDlgItemMessageA]
512
        test    eax, eax
513
        jz      @f
514
        push    1024
515
        push    esi
516
        push    IDC_EXTENSIONS
517
        push    ebx
518
        call    [GetDlgItemTextA]
519
@@:
520
.scan1loop:
521
        mov     edi, assoc_ext
522
        call    find_ext
523
        jz      @f
524
        call    add_assoc
525
@@:
526
        lodsb
527
        call    is_ext_delim
528
        jnz     @b
529
        test    al, al
530
        jz      @f
531
        cmp     byte [esi], 0
532
        jnz     .scan1loop
533
@@:
534
        mov     esi, assoc_ext
535
        cmp     byte [esi], 0
536
        jz      .scan2done
537
.scan2loop:
538
        mov     edi, cur_ext
539
        call    find_ext
540
        jz      @f
541
        call    del_assoc
542
@@:
543
        lodsb
544
        call    is_ext_delim
545
        jnz     @b
546
        test    al, al
547
        jz      @f
548
        cmp     byte [esi], 0
549
        jnz     .scan2loop
550
@@:
551
.scan2done:
552
        pop     edi
553
.nomodify_notempty_assoc:
554
        pop     esi
555
        jmp     .close
556
 
557
.init:
558
; window icons
559
        push    0
560
        push    16
561
        push    16
562
        push    1
563
        push    IDI_ICON1
564
        push    400000h
565
        call    [LoadImageA]
566
        push    eax
567
        push    0
568
        push    80h
569
        push    ebx
570
        call    [SendMessageA]
571
        push    0
572
        push    32
573
        push    32
574
        push    1
575
        push    IDI_ICON1
576
        push    400000h
577
        call    [LoadImageA]
578
        push    eax
579
        push    1
580
        push    80h
581
        push    ebx
582
        call    [SendMessageA]
583
; ramdisk
584
        push    full_ini_name   ; lpFileName
585
        push    512             ; nSize
586
        push    cur_ini_param   ; lpReturnedString
587
        push    null            ; lpDefault
588
        push    ramdisk_keyname ; lpKeyName
589
        push    aDisk           ; lpAppName
590
        call    [GetPrivateProfileStringA]
591
        push    cur_ini_param
592
        push    IDC_RAMDISK
593
        push    ebx
594
        call    [SetDlgItemTextA]
595
; hard disks
596
        push    4
597
        pop     ecx
598
@@:
599
        push    ecx
600
        push    aHdN
601
        push    0
602
        push    180h            ; LB_ADDSTRING
603
        push    IDC_HD_DEV
604
        push    ebx
605
        call    [SendDlgItemMessageA]
606
        inc     [aHdN+3]
607
        pop     ecx
608
        loop    @b
609
        push    esi
610
        xor     esi, esi
611
.readhd:
612
        push    full_ini_name   ; lpFileName
613
        push    0               ; nDefault
614
        push    aHdNn           ; lpKeyName
615
        push    aDisk           ; lpAppName
616
        call    [GetPrivateProfileIntA]
617
        inc     [aHdNn+2]
618
        mov     [hdns+esi*4], eax
619
        and     [hdpart+esi*4], 0
620
        push    edi
621
        test    eax, eax
622
        jz      .nopart
623
        shl     eax, 9
624
        push    eax
625
        push    0
626
        push    [hHeap]
627
        call    [HeapAlloc]
628
        mov     edi, eax
629
        mov     [hdpart+esi*4], eax
630
        push    1
631
.1:
632
        push    dword [esp]
633
        push    esi
634
        push    aHdNM
635
        push    cur_ini_name
636
        call    [wsprintfA]
637
        add     esp, 10h
638
        mov     byte [edi+511], 0
639
        push    full_ini_name
640
        push    511
641
        push    edi
642
        push    null
643
        push    cur_ini_name
644
        push    aDisk
645
        call    [GetPrivateProfileStringA]
646
        mov     eax, edi
647
@@:
648
        inc     eax
649
        cmp     byte [eax], 0
650
        jnz     @b
651
        sub     eax, 9
652
        cmp     eax, edi
653
        jbe     @f
654
        cmp     byte [eax], ','
655
        jnz     @f
656
        cmp     dword [eax+1], 'read'
657
        jnz     @f
658
        cmp     dword [eax+5], 'only'
659
        jnz     @f
660
        mov     byte [eax], 0
661
        mov     byte [edi+511], 1
662
@@:
663
        add     edi, 512
664
        pop     ecx
665
        inc     ecx
666
        cmp     ecx, [hdns+esi*4]
667
        ja      .nopart
668
        push    ecx
669
        jmp     .1
670
.nopart:
671
        pop     edi
672
        inc     esi
673
        cmp     esi, 4
674
        jb      .readhd
675
        pop     esi
676
        push    0
677
        push    0
678
        push    186h            ; LB_SETCURSEL
679
        push    IDC_HD_DEV
680
        push    ebx
681
        call    [SendDlgItemMessageA]
682
        call    OnSelectHdDev
683
; skin
684
        push    full_ini_name   ; lpFileName
685
        push    512             ; nSize
686
        push    cur_ini_param   ; lpReturnedString
687
        push    null            ; lpDefault
688
        push    aSkin           ; lpKeyName
689
        push    aMain           ; lpAppName
690
        call    [GetPrivateProfileStringA]
691
        push    cur_ini_param
692
        push    IDC_SKIN
693
        push    ebx
694
        call    [SetDlgItemTextA]
695
; fonts
696
        push    full_ini_name   ; lpFileName
697
        push    512             ; nSize
698
        push    cur_ini_param   ; lpReturnedString
699
        push    null            ; lpDefault
700
        push    aFont1          ; lpKeyName
701
        push    aMain           ; lpAppName
702
        call    [GetPrivateProfileStringA]
703
        push    cur_ini_param
704
        push    IDC_FONT1
705
        push    ebx
706
        call    [SetDlgItemTextA]
707
        push    full_ini_name   ; lpFileName
708
        push    512             ; nSize
709
        push    cur_ini_param   ; lpReturnedString
710
        push    null            ; lpDefault
711
        push    aFont2          ; lpKeyName
712
        push    aMain           ; lpAppName
713
        call    [GetPrivateProfileStringA]
714
        push    cur_ini_param
715
        push    IDC_FONT2
716
        push    ebx
717
        call    [SetDlgItemTextA]
718
        push    emptyExt
719
        call    check_association
720
        mov     [bWasEmptyAssoc], eax
721
        push    0
722
        push    eax
723
        push    0F1h    ; BM_SETCHECK
724
        push    IDC_EMPTY_EXT
725
        push    ebx
726
        call    [SendDlgItemMessageA]
727
        push    esi edi
728
        xor     esi, esi
729
        mov     edi, assoc_ext
730
.enum:
731
        push    1024
732
        mov     eax, esp
733
        push    0
734
        push    0
735
        push    0
736
        push    0
737
        push    eax
738
        push    cur_ext
739
        push    esi
740
        push    80000000h
741
        call    [RegEnumKeyExA]
742
        test    eax, eax
743
        pop     eax
744
        jnz     .enum_done
745
        cmp     byte [cur_ext], '.'
746
        jnz     .next
747
        cmp     byte [cur_ext+1], 0
748
        jz      .next
749
        push    cur_ext
750
        call    check_association
751
        jz      .next
752
        push    esi
753
        mov     esi, cur_ext+1
754
@@:
755
        lodsb
756
        stosb
757
        test    al, al
758
        jnz     @b
759
        mov     byte [edi-1], ';'
760
        pop     esi
761
.next:
762
        inc     esi
763
        jmp     .enum
764
.enum_done:
765
        mov     byte [edi], 0
766
        pop     edi esi
767
        xor     eax, eax
768
        cmp     byte [assoc_ext], 0
769
        setnz   al
770
        push    0
771
        push    eax
772
        push    0F1h
773
        push    IDC_NOTEMPTY_EXT
774
        push    ebx
775
        call    [SendDlgItemMessageA]
776
        cmp     byte [assoc_ext], 0
777
        jz      .no_custom
778
        push    assoc_ext
779
        push    IDC_EXTENSIONS
780
        push    ebx
781
        call    [SetDlgItemTextA]
782
        jmp     .assoc_done
783
.no_custom:
784
        push    def_custom_assoc
785
        push    IDC_EXTENSIONS
786
        push    ebx
787
        call    [SetDlgItemTextA]
788
        push    0
789
        mov     ecx, IDC_EXTENSIONS
790
        call    enable_part_items.1
791
        pop     eax
792
.assoc_done:
793
        pop     ebx
794
        xor     eax, eax
795
        ret     16
796
 
797
set_cur_part:
798
        cmp     [cur_hd_dev], -1
799
        jz      .ret
800
        cmp     [cur_hd_part], -1
801
        jnz     @f
802
.ret:
803
        ret
804
@@:
805
        push    eax ecx
806
        mov     ecx, [cur_hd_part]
807
        mov     eax, [cur_hd_dev]
808
        shl     ecx, 9
809
        add     ecx, [hdpart+eax*4]
810
        push    ecx
811
        push    510
812
        push    ecx
813
        push    IDC_PARTITION
814
        push    ebx
815
        call    [GetDlgItemTextA]
816
        push    dword [esp]
817
        call    [GetFileAttributesA]
818
        cmp     eax, -1
819
        jz      .err
820
        test    al, 10h
821
        jz      .err
822
        push    0
823
        push    0
824
        push    0F0h    ; BM_GETCHECK
825
        push    IDC_CHECK1
826
        push    ebx
827
        call    [SendDlgItemMessageA]
828
        pop     ecx
829
        mov     [ecx+511], al
830
        call    add_trailing_slash
831
        pop     ecx eax
832
        ret
833
.err:
834
        push    10h
835
        push    0
836
        push    aInvalidPath
837
        push    ebx
838
        call    [MessageBoxA]
839
        pop     ecx
840
        pop     ecx eax
841
        pop     eax eax
842
        push    0
843
        push    [cur_hd_dev]
844
        push    186h
845
        push    IDC_HD_DEV
846
        push    ebx
847
        call    [SendDlgItemMessageA]
848
        push    0
849
        push    [cur_hd_part]
850
        push    186h
851
        push    IDC_HD_PART
852
        push    ebx
853
        call    [SendDlgItemMessageA]
854
        call    focus_on_path
855
        jmp     DlgProc.true
856
 
857
focus_on_path:
858
        push    IDC_PARTITION
859
        push    ebx
860
        call    [GetDlgItem]
861
        push    eax
862
        call    [SetFocus]
863
        ret
864
 
865
add_trailing_slash:
866
        inc     ecx
867
        cmp     byte [ecx], 0
868
        jnz     add_trailing_slash
869
        cmp     byte [ecx-1], '\'
870
        jz      @f
871
        mov     word [ecx], '\'
872
@@:
873
        ret
874
 
875
enable_part_items:
876
        push    eax
877
        mov     ecx, IDC_PATH_STRING
878
        call    .1
879
        mov     ecx, IDC_PARTITION
880
        call    .1
881
        mov     ecx, IDC_PARTITION_BROWSE
882
        call    .1
883
        mov     ecx, IDC_CHECK1
884
        call    .1
885
        pop     eax
886
        ret
887
 
888
.1:
889
        push    ecx
890
        push    ebx
891
        call    [GetDlgItem]
892
        push    dword [esp+4]
893
        push    eax
894
        call    [EnableWindow]
895
        ret
896
 
897
OnSelectHdDev:
898
        push    0
899
        push    0
900
        push    188h            ; LB_GETCURSEL
901
        push    IDC_HD_DEV
902
        push    ebx
903
        call    [SendDlgItemMessageA]
904
        cmp     eax, 4
905
        jae     .ret
906
        call    set_cur_part
907
        mov     [cur_hd_dev], eax
908
        or      [cur_hd_part], -1
909
        push    eax
910
        xor     eax, eax
911
        call    enable_part_items
912
        push    null
913
        push    IDC_PARTITION
914
        push    ebx
915
        call    [SetDlgItemTextA]
916
        push    0
917
        push    0
918
        push    0F1h            ; BM_SETCHECK
919
        push    IDC_CHECK1
920
        push    ebx
921
        call    [SendDlgItemMessageA]
922
        push    0
923
        push    0
924
        push    184h            ; LB_RESETCONTENT
925
        push    IDC_HD_PART
926
        push    ebx
927
        call    [SendDlgItemMessageA]
928
        pop     eax
929
        cmp     dword [hdns+eax*4], 0
930
        jnz     .haspart
931
        push    aNone
932
        push    0
933
        push    180h            ; LB_ADDSTRING
934
        push    IDC_HD_PART
935
        push    ebx
936
        call    [SendDlgItemMessageA]
937
        push    0
938
.done:
939
        mov     ecx, IDC_HD_PART
940
        call    enable_part_items.1
941
        mov     ecx, IDC_DEL_PARTITION
942
        call    enable_part_items.1
943
        pop     eax
944
.ret:
945
        ret
946
.haspart:
947
        push    esi
948
        mov     esi, eax
949
        push    1
950
@@:
951
        push    dword [esp]
952
        push    esi
953
        push    aHdNM2
954
        push    cur_ini_name
955
        call    [wsprintfA]
956
        add     esp, 10h
957
        push    cur_ini_name
958
        push    0
959
        push    180h
960
        push    IDC_HD_PART
961
        push    ebx
962
        call    [SendDlgItemMessageA]
963
        pop     ecx
964
        inc     ecx
965
        cmp     ecx, [hdns+esi*4]
966
        ja      @f
967
        push    ecx
968
        jmp     @b
969
@@:
970
        pop     esi
971
        push    1
972
        jmp     .done
973
 
974
OnSelectHdPart:
975
        push    0
976
        push    0
977
        push    188h
978
        push    IDC_HD_PART
979
        push    ebx
980
        call    [SendDlgItemMessageA]
981
        mov     ecx, [cur_hd_dev]
982
        cmp     eax, [hdns+ecx*4]
983
        jae     .ret
984
        call    set_cur_part
985
        mov     [cur_hd_part], eax
986
        mov     ecx, [hdpart+ecx*4]
987
        shl     eax, 9
988
        add     ecx, eax
989
        push    ecx
990
        movzx   eax, byte [ecx+511]
991
        push    0
992
        push    eax
993
        push    0F1h    ; BM_SETCHECK
994
        push    IDC_CHECK1
995
        push    ebx
996
        call    [SendDlgItemMessageA]
997
        push    IDC_PARTITION
998
        push    ebx
999
        call    [SetDlgItemTextA]
1000
        xor     eax, eax
1001
        inc     eax
1002
        call    enable_part_items
1003
        call    focus_on_path
1004
.ret:
1005
        ret
1006
 
1007
check_association:
1008
        push    hkey
1009
        push    1       ; KEY_QUERY_VALUE
1010
        push    0
1011
        push    dword [esp+16]
1012
        push    80000000h       ; HKEY_CLASSES_ROOT
1013
        call    [RegOpenKeyExA]
1014
        test    eax, eax
1015
        jnz     .not
1016
        push    1000
1017
        push    esp
1018
        push    cur_ini_param
1019
        push    0
1020
        push    0
1021
        push    0
1022
        push    [hkey]
1023
        call    [RegQueryValueExA]
1024
        mov     [esp], eax
1025
        push    [hkey]
1026
        call    [RegCloseKey]
1027
        pop     eax
1028
        test    eax, eax
1029
        jnz     .not
1030
        push    esi edi
1031
        mov     edi, cur_ini_param
1032
@@:
1033
        inc     edi
1034
        cmp     byte [edi-1], 0
1035
        jnz     @b
1036
        dec     edi
1037
        mov     esi, aShellOpenCommand
1038
@@:
1039
        lodsb
1040
        stosb
1041
        test    al, al
1042
        jnz     @b
1043
        pop     edi esi
1044
        push    hkey
1045
        push    1
1046
        push    0
1047
        push    cur_ini_param
1048
        push    80000000h
1049
        call    [RegOpenKeyExA]
1050
        test    eax, eax
1051
        jnz     .not
1052
        push    1024
1053
        push    esp
1054
        push    cur_ini_param
1055
        push    0
1056
        push    0
1057
        push    0
1058
        push    [hkey]
1059
        call    [RegQueryValueExA]
1060
        mov     [esp], eax
1061
        push    [hkey]
1062
        call    [RegCloseKey]
1063
        pop     eax
1064
        test    eax, eax
1065
        jnz     .not
1066
        push    esi edi
1067
        mov     edi, cur_ini_param
1068
.scan:
1069
        cmp     byte [edi], 0
1070
        jz      .scanno
1071
        mov     esi, ExeFileName
1072
        mov     ecx, ExeFileNameLen
1073
        push    edi
1074
        repz    cmpsb
1075
        pop     edi
1076
        jz      .scanok
1077
        inc     edi
1078
        jmp     .scan
1079
.scanno:
1080
        pop     edi esi
1081
.not:
1082
        xor     eax, eax
1083
        ret     4
1084
.scanok:
1085
        pop     edi esi
1086
        xor     eax, eax
1087
        inc     eax
1088
        ret     4
1089
 
1090
add_assoc:
1091
        call    form_ext_name
1092
        push    ebx
1093
        xor     ebx, ebx
1094
        push    ebx
1095
        push    hkey
1096
        push    ebx
1097
        push    2       ; KEY_SET_VALUE
1098
        push    ebx
1099
        push    ebx
1100
        push    ebx
1101
        push    edi
1102
        push    80000000h
1103
        call    [RegCreateKeyExA]
1104
        test    eax, eax
1105
        jnz     .ret
1106
        push    aKolibriExecutable.size
1107
        push    aKolibriExecutable
1108
        push    1       ; REG_SZ
1109
        push    ebx
1110
        push    ebx
1111
        push    [hkey]
1112
        call    [RegSetValueExA]
1113
        push    eax
1114
        push    [hkey]
1115
        call    [RegCloseKey]
1116
        pop     eax
1117
        test    eax, eax
1118
        jnz     .ret
1119
        push    ebx
1120
        push    hkey
1121
        push    ebx
1122
        push    6       ; KEY_SET_VALUE + KEY_CREATE_SUB_KEY
1123
        push    ebx
1124
        push    ebx
1125
        push    ebx
1126
        push    aKolibriExecutable
1127
        push    80000000h
1128
        call    [RegCreateKeyExA]
1129
        test    eax, eax
1130
        jnz     .ret
1131
        push    edi
1132
        mov     edi, cur_ini_param
1133
        mov     al, '"'
1134
        stosb
1135
        call    get_exe_name
1136
        mov     al, '"'
1137
        stosb
1138
        mov     eax, ' "%1'
1139
        stosd
1140
        mov     al, '"'
1141
        stosb
1142
        mov     al, 0
1143
        stosb
1144
        push    [hkey]
1145
        push    ebx
1146
        push    hkey
1147
        push    ebx
1148
        push    2       ; KEY_SET_VALUE
1149
        push    ebx
1150
        push    ebx
1151
        push    ebx
1152
        push    aShellOpenCommand2
1153
        push    [hkey]
1154
        call    [RegCreateKeyExA]
1155
        test    eax, eax
1156
        jnz     .ret2
1157
        mov     eax, cur_ini_param
1158
        sub     edi, eax
1159
        push    edi
1160
        push    eax
1161
        push    1
1162
        push    ebx
1163
        push    ebx
1164
        push    [hkey]
1165
        call    [RegSetValueExA]
1166
        push    [hkey]
1167
        call    [RegCloseKey]
1168
        mov     edi, cur_ini_param
1169
        call    get_exe_name
1170
        mov     al, 0
1171
        stosb
1172
        pop     eax
1173
        push    eax
1174
        push    ebx
1175
        push    hkey
1176
        push    ebx
1177
        push    2
1178
        push    ebx
1179
        push    ebx
1180
        push    ebx
1181
        push    aDefaultIcon
1182
        push    eax
1183
        call    [RegCreateKeyExA]
1184
        test    eax, eax
1185
        jnz     .ret2
1186
        mov     eax, cur_ini_param
1187
        sub     edi, eax
1188
        push    edi
1189
        push    eax
1190
        push    1
1191
        push    ebx
1192
        push    ebx
1193
        push    [hkey]
1194
        call    [RegSetValueExA]
1195
        push    [hkey]
1196
        call    [RegCloseKey]
1197
.ret2:
1198
        call    [RegCloseKey]
1199
        pop     edi
1200
.ret:
1201
        pop     ebx
1202
        ret
1203
 
1204
del_assoc:
1205
        call    form_ext_name
1206
        push    edi
1207
        push    80000000h
1208
        call    [RegDeleteKeyA]
1209
        ret
1210
 
1211
form_ext_name:
1212
        push    esi
1213
        mov     edi, cur_ini_param
1214
        push    edi
1215
        mov     al, '.'
1216
        stosb
1217
@@:
1218
        lodsb
1219
        stosb
1220
        call    is_ext_delim
1221
        jnz     @b
1222
        mov     byte [edi-1], 0
1223
        pop     edi esi
1224
        ret
1225
 
1226
get_exe_name:
1227
        push    esi
1228
        mov     esi, full_ini_name
1229
@@:
1230
        lodsb
1231
        stosb
1232
        test    al, al
1233
        jnz     @b
1234
@@:
1235
        dec     edi
1236
        cmp     byte [edi-1], '\'
1237
        jnz     @b
1238
        mov     esi, ExeFileName
1239
        mov     ecx, ExeFileNameLen
1240
        rep     movsb
1241
        pop     esi
1242
        ret
1243
 
1244
check_file_exists:
1245
        push    ecx
1246
        push    512
1247
        push    cur_ini_param
1248
        push    ecx
1249
        push    ebx
1250
        call    [GetDlgItemTextA]
1251
        push    cur_ini_param
1252
        call    [GetFileAttributesA]
1253
        inc     eax
1254
        jz      .err
1255
        pop     ecx
1256
        ret
1257
.err:
1258
        push    10h
1259
        push    0
1260
        push    aInvalidFile
1261
        push    ebx
1262
        call    [MessageBoxA]
1263
        push    ebx
1264
        call    [GetDlgItem]
1265
        push    eax
1266
        call    [SetFocus]
1267
        pop     eax
1268
        jmp     DlgProc.true
1269
 
1270
find_ext:
1271
        push    esi
1272
@@:
1273
        lodsb
1274
        scasb
1275
        jnz     @f
1276
        call    is_ext_delim
1277
        jnz     @b
1278
.ret:
1279
        pop     esi
1280
        ret
1281
@@:
1282
        call    is_ext_delim
1283
        jnz     .next
1284
        mov     al, byte [edi-1]
1285
        call    is_ext_delim
1286
        jz      .ret
1287
.next:
1288
        pop     esi
1289
        dec     edi
1290
@@:
1291
        inc     edi
1292
        mov     al, byte [edi-1]
1293
        call    is_ext_delim
1294
        jnz     @b
1295
        test    al, al
1296
        jz      @f
1297
        cmp     byte [edi], 0
1298
        jnz     find_ext
1299
@@:
1300
        inc     edi
1301
        ret
1302
 
1303
is_ext_delim:
1304
        test    al, al
1305
        jz      @f
1306
        cmp     al, ','
1307
        jz      @f
1308
        cmp     al, ';'
1309
@@:     ret
1310
 
1311
align 4
1312
data import
1313
macro thunk a {
1314
a#_thunk:dw 0
1315
db `a,0}
1316
        dd      0,0,0, rva kernel32_name, rva kernel32_thunks
1317
        dd      0,0,0, rva user32_name, rva user32_thunks
1318
        dd      0,0,0, rva advapi32_name, rva advapi32_thunks
1319
        dd      0,0,0, rva shell32_name, rva shell32_thunks
1320
        dd      0,0,0, rva ole32_name, rva ole32_thunks
1321
        dd      0,0,0, rva comdlg32_name, rva comdlg32_thunks
1322
        dd      0,0,0,0,0
1323
kernel32_name   db      'kernel32.dll',0
1324
user32_name     db      'user32.dll',0
1325
advapi32_name   db      'advapi32.dll',0
1326
comdlg32_name   db      'comdlg32.dll',0
1327
shell32_name    db      'shell32.dll',0
1328
ole32_name      db      'ole32.dll',0
1329
kernel32_thunks:
1330
GetFileAttributesA      dd      rva GetFileAttributesA_thunk
1331
CreateFileA             dd      rva CreateFileA_thunk
1332
WriteFile               dd      rva WriteFile_thunk
1333
CloseHandle             dd      rva CloseHandle_thunk
1334
SetCurrentDirectoryA	dd	rva SetCurrentDirectoryA_thunk
1335
GetPrivateProfileIntA   dd      rva GetPrivateProfileIntA_thunk
1336
GetPrivateProfileStringA dd     rva GetPrivateProfileStringA_thunk
1337
WritePrivateProfileStringA dd   rva WritePrivateProfileStringA_thunk
1338
GetModuleFileNameA      dd      rva GetModuleFileNameA_thunk
1339
GetProcessHeap          dd      rva GetProcessHeap_thunk
1340
HeapAlloc               dd      rva HeapAlloc_thunk
1341
HeapReAlloc             dd      rva HeapReAlloc_thunk
1342
ExitProcess             dd      rva ExitProcess_thunk
1343
                        dw      0
1344
thunk GetFileAttributesA
1345
thunk CreateFileA
1346
thunk WriteFile
1347
thunk CloseHandle
1348
thunk SetCurrentDirectoryA
1349
thunk GetPrivateProfileIntA
1350
thunk GetPrivateProfileStringA
1351
thunk WritePrivateProfileStringA
1352
thunk GetModuleFileNameA
1353
thunk GetProcessHeap
1354
thunk HeapAlloc
1355
thunk HeapReAlloc
1356
thunk ExitProcess
1357
user32_thunks:
1358
DialogBoxParamA         dd      rva DialogBoxParamA_thunk
1359
EndDialog               dd      rva EndDialog_thunk
1360
GetDlgItem              dd      rva GetDlgItem_thunk
1361
GetDlgItemTextA         dd      rva GetDlgItemTextA_thunk
1362
SetDlgItemTextA         dd      rva SetDlgItemTextA_thunk
1363
EnableWindow            dd      rva EnableWindow_thunk
1364
SendDlgItemMessageA     dd      rva SendDlgItemMessageA_thunk
1365
wsprintfA               dd      rva wsprintfA_thunk
1366
MessageBoxA             dd      rva MessageBoxA_thunk
1367
SetFocus                dd      rva SetFocus_thunk
1368
LoadImageA              dd      rva LoadImageA_thunk
1369
SendMessageA            dd      rva SendMessageA_thunk
1370
                        dw      0
1371
thunk DialogBoxParamA
1372
thunk EndDialog
1373
thunk GetDlgItem
1374
thunk GetDlgItemTextA
1375
thunk SetDlgItemTextA
1376
thunk EnableWindow
1377
thunk SendDlgItemMessageA
1378
thunk wsprintfA
1379
thunk MessageBoxA
1380
thunk SetFocus
1381
thunk LoadImageA
1382
thunk SendMessageA
1383
advapi32_thunks:
1384
RegOpenKeyExA           dd      rva RegOpenKeyExA_thunk
1385
RegQueryValueExA        dd      rva RegQueryValueExA_thunk
1386
RegCloseKey             dd      rva RegCloseKey_thunk
1387
RegEnumKeyExA           dd      rva RegEnumKeyExA_thunk
1388
RegDeleteKeyA           dd      rva RegDeleteKeyA_thunk
1389
RegCreateKeyExA         dd      rva RegCreateKeyExA_thunk
1390
RegSetValueExA          dd      rva RegSetValueExA_thunk
1391
                        dw      0
1392
thunk RegOpenKeyExA
1393
thunk RegQueryValueExA
1394
thunk RegCloseKey
1395
thunk RegEnumKeyExA
1396
thunk RegDeleteKeyA
1397
thunk RegCreateKeyExA
1398
thunk RegSetValueExA
1399
comdlg32_thunks:
1400
GetOpenFileNameA        dd      rva GetOpenFileNameA_thunk
1401
                        dw      0
1402
thunk GetOpenFileNameA
1403
ole32_thunks:
1404
CoInitializeEx          dd      rva CoInitializeEx_thunk
1405
CoUninitialize          dd      rva CoUninitialize_thunk
1406
                        dw      0
1407
thunk CoInitializeEx
1408
thunk CoUninitialize
1409
shell32_thunks:
1410
SHGetMalloc             dd      rva SHGetMalloc_thunk
1411
SHBrowseForFolder       dd      rva SHBrowseForFolder_thunk
1412
SHGetPathFromIDList     dd      rva SHGetPathFromIDList_thunk
1413
                        dw      0
1414
thunk SHGetMalloc
1415
thunk SHBrowseForFolder
1416
thunk SHGetPathFromIDList
1417
end data
1418
 
1419
align 10h
1420
data resource from 'config.res'
1421
end data
1422
 
1423
section '.data' data readable writable
1424
 
1425
IniFileName     db      'KlbrInWin.ini',0
1426
ExeFileName     db      'KlbrInWin.exe'
1427
ExeFileNameLen = $ - ExeFileName
1428
null            db      0
1429
aDisk           db      'Disk',0
1430
aMain           db      'Main',0
1431
ramdisk_keyname db      'RamDisk',0
1432
aSkin           db      'Skin',0
1433
aFont1          db      'Font1',0
1434
aFont2          db      'Font2',0
1435
aHdN            db      '/hd0',0
1436
aHdNn           db      'hd0n',0
1437
aHdNM           db      'hd%d_%d',0
1438
aHdNM2          db      '/hd%d/%d',0
1439
aNone           db      '(none)',0
1440
emptyExt        db      '.',0
1441
def_custom_assoc db     'kex;',0
1442
aShellOpenCommand db    '\'
1443
aShellOpenCommand2 db   'shell\open\command',0
1444
aKolibriExecutable db   'KolibriExecutable',0
1445
.size = $ - aKolibriExecutable
1446
aDefaultIcon    db      'DefaultIcon',0
1447
ini:
1448
        file    'config.ini'
1449
ini_size = $ - ini
1450
 
1451
align 4
1452
ofn:
1453
        dd      76      ; lStructSize
1454
        dd      0       ; hWndOwner
1455
        dd      0       ; hInstance
1456
filter  dd      0       ; lpstrFilter
1457
        dd      0       ; lpstrCustomFilter
1458
        dd      0       ; nMaxCustFilter
1459
        dd      0       ; nFilterIndex
1460
        dd      cur_ini_param   ; lpstrFile
1461
        dd      512     ; nMaxFile
1462
        dd      0       ; lpstrFileTitle
1463
        dd      0       ; nMaxFileTitle
1464
        dd      0       ; lpstrInitialDir
1465
;        dd      ofn_title       ; lpstrTitle
1466
        dd      0
1467
        dd      81804h  ; flags
1468
        dw      0       ; nFileOffset
1469
        dw      0       ; nFileExtension
1470
        dd      0       ; lpstrDefExt
1471
        dd      0       ; lCustData
1472
        dd      0       ; lpfnHook
1473
        dd      0       ; lpTemplateName
1474
 
1475
bi:
1476
        dd      0       ; hwndOwner
1477
        dd      0       ; pidlRoot
1478
        dd      cur_ini_param   ; pszDisplayName
1479
        dd      bi_title; lpszTitle
1480
        dd      1       ; BIF_RETURNONLYFSDIRS
1481
        dd      0       ; lpfn
1482
        dd      0       ; lParam
1483
        dd      0       ; iImage
1484
 
1485
cur_hd_dev      dd      -1
1486
cur_hd_part     dd      -1
1487
 
1488
bWasEmptyAssoc  dd      0
1489
 
1490
skn_filter      db      'Skin files (*.skn)',0,'*.skn',0,'All files (*.*',0,'*.*',0,0
1491
mt_filter       db      'Files *.mt',0,'*.mt',0,'All files (*.*)',0,'*.*',0,0
1492
 
1493
bi_title        db      'Select folder for root of emulated file system:',0
1494
 
1495
aInvalidPath    db      'Entered path is invalid or does not specify a directory',0
1496
aInvalidFile    db      'The mentioned file does not exist',0
1497
aTooManyPartitions db   'Too many partitions! (maximum 255 per device is allowed)',0
1498
 
1499
align 4
1500
hHeap           dd      ?
1501
hkey            dd      ?
1502
pathzeroptr	dd	?
1503
full_ini_name   rb      1024
1504
cur_ini_param   rb      1024
1505
cur_ini_name    rb      32
1506
hdns            rd      4
1507
hdpart          rd      4
1508
cur_ext         rb      1024
1509
assoc_ext       rb      1024