Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

merge with translations

Changeset 906363e76fc7

Parents 887a043dd524

Parents c11857fe9b23

by Steve Borho

Changes to 31 files · Browse files at 906363e76fc7 Showing diff from parent 887a043dd524 c11857fe9b23 Diff from another changeset...

Change 1 of 1 Show Entire File contrib/​hgtk.cmd Stacked
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@@ -1,16 +1,16 @@
-:: -:: Win32 batch file for running the TortoiseHg hgtk script. -:: - -@echo off -setlocal - -:: Uncomment the line below and modify accoringly -::set hgtkpath="C:\repos\tortoisehg-crew\hgtk" -if not exist %hgtkpath% goto :notfound -python %hgtkpath% %* -goto end - -:notfound -echo hgtk: Please configure kgtkpath in %~f0 -:end +:: +:: Win32 batch file for running the TortoiseHg hgtk script. +:: + +@echo off +setlocal + +:: Uncomment the line below and modify accoringly +::set hgtkpath="C:\repos\tortoisehg-crew\hgtk" +if not exist %hgtkpath% goto :notfound +python %hgtkpath% %* +goto end + +:notfound +echo hgtk: Please configure kgtkpath in %~f0 +:end
Change 1 of 1 Show Entire File contrib/​rpm.sh Stacked
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
@@ -0,0 +1,7 @@
+#!/bin/sh + +mkdir -p rpmbuild/{SOURCES,BUILD} +hg archive -t tgz rpmbuild/SOURCES/tortoisehg-hg.tgz +rpmbuild --define "_topdir $(pwd)/rpmbuild" -ba $(dirname $0)/tortoisehg.spec +rm -rf rpmbuild/BUILD/ +ls -l rpmbuild/{RPMS/*,SRPMS}/tortoisehg-*.rpm
Change 1 of 1 Show Entire File contrib/​tortoisehg.spec Stacked
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -0,0 +1,73 @@
+%{!?python_sitelib: %global python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")} +# Pure python package +%define debug_package %{nil} + +Name: tortoisehg +Version: hg +Release: hg +Summary: Mercurial GUI command line tool hgtk +Group: Development/Tools +License: GPLv2 +URL: http://bitbucket.org/tortoisehg/stable/wiki/ +Source0: tortoisehg-hg.tgz +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildRequires: python +Requires: python >= 2.4, mercurial >= 1.1.2, gnome-python2-gconf +Requires: gnome-python2-gtksourceview, pycairo, pygobject2, pygtk2 >= 2.10 + +%description +This package contains the hgtk command line tool which provides a +graphical user interface to the Mercurial distributed revision control system. + +%package nautilus +Summary: Mercurial GUI plugin to Nautilus file manager +Group: Development/Tools +Requires: %{name} nautilus-python + +%description nautilus +This package contains the TortoiseHg Gnome/Nautilus extension, +which makes the Mercurial distributed revision control +system available in the file manager with a graphical interface. + +%prep +%setup -q -n tortoisehg-hg + +cat > thgutil/config.py << EOT +bin_path = "%{_bindir}" +license_path = "%{_docdir}/%{name}-%{version}/COPYING.txt" +locale_path = "%{_datadir}/locale" +icon_path = "%{_datadir}/pixmaps/tortoisehg/icons" +EOT + +%build +%{__python} setup.py build + +%install +rm -rf $RPM_BUILD_ROOT + +%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT + +install -m 644 -D contrib/_hgtk $RPM_BUILD_ROOT/%{_datadir}/zsh/site-functions/_hgtk + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root,-) +%doc COPYING.txt ReleaseNotes.txt +%{_bindir}/hgtk +%{python_sitelib}/hggtk/ +%{python_sitelib}/thgutil/ +%{python_sitelib}/tortoisehg-*.egg-info +%{_datadir}/pixmaps/tortoisehg/ +%{_datadir}/locale/*/LC_MESSAGES/tortoisehg.mo +# /usr/share/zsh/site-functions/ is owned by zsh package which we don't want to +# require. We also don't want to create a sub-package just for this dependency. +# Instead we just claim ownership of the zsh top folder ... +%{_datadir}/zsh + +%files nautilus +%defattr(-,root,root,-) +%{_libdir}/nautilus/extensions-2.0/python/nautilus-thg.py* + +%changelog
Change 1 of 1 Show Entire File contrib/​win32/​config.py Stacked
renamed from contrib/win32/__paths__.py
 
1
2
 
3
4
5
6
7
8
9
 
10
11
12
 
1
 
2
3
4
5
6
7
8
 
9
10
11
12
@@ -1,12 +1,12 @@
 """ -__paths__.py +config.py   Copyright (C) 2009 Steve Borho <steve@borho.org>    This software may be used and distributed according to the terms  of the GNU General Public License, incorporated herein by reference.  """   -# This version of __paths__.py is used in the binary installer +# This version of config.py is used in the binary installer  # distributions of TortoiseHg on Windows. Since we no longer need to  # worry about Python shell extensions, we can use the path of the  # current executable to find our package data.
 
112
113
114
 
 
115
116
117
 
112
113
114
115
116
117
118
119
@@ -112,6 +112,8 @@
  self.curnodes = (parent, ctx.node())   if len(self._filelist) > 1:   self._filesel.select_path((1,)) + else: + self._filesel.select_path((0,))     def filelist_rowchanged(self, sel):   model, path = sel.get_selected()
Change 1 of 1 Show Entire File hggtk/​commit.py Stacked
 
463
464
465
466
 
 
 
467
 
 
 
468
469
470
 
463
464
465
 
466
467
468
469
470
471
472
473
474
475
@@ -463,8 +463,13 @@
  if dopatch:   try:   pfiles = {} - patch.internalpatch(fp, ui, 1, repo.root, files=pfiles, + if patch.patchfile.__bases__: + # Mercurial 1.3 + patch.internalpatch(fp, ui, 1, repo.root, files=pfiles,   eolmode=None) + else: + # Mercurial 1.2 + patch.internalpatch(fp, ui, 1, repo.root, files=pfiles)   patch.updatedir(ui, repo, pfiles)   except patch.PatchError, err:   s = str(err)
Change 1 of 2 Show Entire File hggtk/​hgshelve.py Stacked
 
438
439
440
441
 
442
443
444
 
501
502
503
504
 
 
 
 
 
 
505
506
507
 
438
439
440
 
441
442
443
444
 
501
502
503
 
504
505
506
507
508
509
510
511
512
@@ -438,7 +438,7 @@
    def shelvefunc(ui, repo, message, match, opts):   # If an MQ patch is applied, consider all qdiff changes - if hasattr(repo, 'mq') and repo.mq.applied: + if hasattr(repo, 'mq') and repo.mq.applied and repo['.'] == repo['qtip']:   qtip = repo['.']   basenode = qtip.parents()[0].node()   else: @@ -501,7 +501,12 @@
  if dopatch:   ui.debug(_('applying patch\n'))   ui.debug(fp.getvalue()) - patch.internalpatch(fp, ui, 1, repo.root, eolmode=None) + if patch.patchfile.__bases__: + # Mercurial 1.3 + patch.internalpatch(fp, ui, 1, repo.root, eolmode=None) + else: + # Mercurial 1.2 + patch.internalpatch(fp, ui, 1, repo.root)   del fp     # 3c. apply filtered patch to clean repo (shelve)
Change 1 of 3 Show Entire File hggtk/​status.py Stacked
 
230
231
232
233
234
 
 
235
236
237
 
551
552
553
554
 
555
556
557
 
1065
1066
1067
1068
1069
1070
1071
 
 
 
 
 
1072
1073
1074
 
230
231
232
 
 
233
234
235
236
237
 
551
552
553
 
554
555
556
557
 
1065
1066
1067
 
 
 
 
1068
1069
1070
1071
1072
1073
1074
1075
@@ -230,8 +230,8 @@
  self.setting_lastpos = settings['gstatus-lastpos']   except KeyError:   pass - self.mqmode = None - if hasattr(self.repo, 'mq') and self.repo.mq.applied: + self.mqmode, repo = None, self.repo + if hasattr(repo, 'mq') and repo.mq.applied and repo['.'] == repo['qtip']:   self.mqmode = True     @@ -551,7 +551,7 @@
  repo = self.repo   hglib.invalidaterepo(repo)   if hasattr(repo, 'mq'): - self.mqmode = repo.mq.applied + self.mqmode = repo.mq.applied and repo['.'] == repo['qtip']   self.set_title(self.get_title())     if self.mqmode and self.mode != 'status': @@ -1065,10 +1065,11 @@
  chunk.write(buf)   buf.seek(0)   try: - fp = open(result, "w") - fp.write(buf.read()) - except OSError: - pass + try: + fp = open(result, "w") + fp.write(buf.read()) + except OSError: + pass   finally:   fp.close()  
Change 1 of 1 Show Entire File hggtk/​synch.py Stacked
 
36
37
38
39
40
41
 
 
 
 
42
43
44
 
36
37
38
 
 
 
39
40
41
42
43
44
45
@@ -36,9 +36,10 @@
    self.saved_stdout = sys.stdout   self.saved_stderr = sys.stderr - # Pipe stderr, stdout to self.write - sys.stdout = self - sys.stderr = self + if os.name == 'nt': + # Pipe stderr, stdout to self.write + sys.stdout = self + sys.stderr = self     # persistent app data   self._settings = settings.Settings('synch')
 
972
973
974
 
 
975
976
977
978
979
980
981
982
983
 
972
973
974
975
976
977
978
979
980
 
 
981
982
983
@@ -972,12 +972,12 @@
  f = open(self.fn, "w")   f.write(str(self.ini))   f.close() + self._btn_apply.set_sensitive(False) + self.dirty = False   except IOError, e:   dialog.error_dialog(self, _('Unable to write configuration file'),   str(e))   - self._btn_apply.set_sensitive(False) - self.dirty = False   return 0    def run(ui, *pats, **opts):
Change 1 of 1 Show Entire File hggtk/​visdiff.py Stacked
 
238
239
240
241
 
242
243
244
 
238
239
240
 
241
242
243
244
@@ -238,7 +238,7 @@
  stderr=subprocess.PIPE,   stdout=subprocess.PIPE,   stdin=subprocess.PIPE) - except (WindowsError, EnvironmentError), e: + except Exception, e:   gdialog.Prompt(_('Tool launch failure'),   _('%s : %s') % (self.diffpath, str(e)), None).run()  
Change 1 of 1 Show Entire File setup.py Stacked
 
117
118
119
120
 
121
122
123
124
125
126
127
128
129
130
131
132
 
 
 
 
 
 
 
 
 
133
134
135
 
117
118
119
 
120
121
122
123
124
125
 
 
 
 
 
 
 
126
127
128
129
130
131
132
133
134
135
136
137
@@ -117,19 +117,21 @@
  _data_files = [(os.path.join('share/pixmaps/tortoisehg', root),   [os.path.join(root, file_) for file_ in files])   for root, dirs, files in os.walk('icons')] - _data_files += [(os.path.join('share/locale', root), + _data_files += [(os.path.join('share', root),   [os.path.join(root, file_) for file_ in files])   for root, dirs, files in os.walk('locale')]   _data_files += [('lib/nautilus/extensions-2.0/python',   ['contrib/nautilus-thg.py'])]   - # Create a __paths__.py. Distributions will need to supply their own - f = open('thgutil/__paths__.py', "w") - f.write('bin_path = "/usr/bin"\n') - f.write('license_path = "/usr/share/doc/tortoisehg/Copying.txt.gz"\n') - f.write('locale_path = "/usr/share/locale"\n') - f.write('icon_path = "/usr/share/pixmaps/tortoisehg/icons"\n') - f.close() + # Create a config.py. Distributions will need to supply their own + cfgfile = os.path.join('thgutil', 'config.py') + if not os.path.exists(cfgfile): + f = open(cfgfile, "w") + f.write('bin_path = "/usr/bin"\n') + f.write('license_path = "/usr/share/doc/tortoisehg/Copying.txt.gz"\n') + f.write('locale_path = "/usr/share/locale"\n') + f.write('icon_path = "/usr/share/pixmaps/tortoisehg/icons"\n') + f.close()     return _scripts, _packages, _data_files, _extra  
Change 1 of 1 Show Entire File thgutil/​paths.py Stacked
 
7
8
9
10
 
11
12
13
 
7
8
9
 
10
11
12
13
@@ -7,7 +7,7 @@
 """    try: - from __paths__ import icon_path, bin_path, license_path, locale_path + from config import icon_path, bin_path, license_path, locale_path  except ImportError:   icon_path, bin_path, license_path, locale_path = None, None, None, None  
 
5
6
7
 
 
8
9
10
 
268
269
270
 
 
271
272
273
 
5
6
7
8
9
10
11
12
 
270
271
272
273
274
275
276
277
@@ -5,6 +5,8 @@
 #include "Dirstatecache.h"  #include "Thgstatus.h"  #include "Winstat.h" +#include <map> +    struct MenuDescription  { @@ -268,6 +270,8 @@
 }     +#define ResultFromShort(i) ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(i))) +  // IContextMenu  STDMETHODIMP  CShellExt::QueryContextMenu(
Change 1 of 1 Show Entire File win32/​shellext/​FixWinDefs.h Stacked
 
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,32 +0,0 @@
-// TortoiseCVS - a Windows shell extension for easy version control - -// Copyright (C) 2003 - Hartmut Honisch -// <Hartmut_Honisch@web.de> - November 2003 - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef FIX_WIN_DEFS_H -#define FIX_WIN_DEFS_H - -#undef SetPort -#undef FindWindow -#undef CreateDialog -#undef GetCharWidth -#undef GetWindowStyle -#undef IsMaximized -#undef GetUsername -#undef min -#undef max - -#endif /* FIX_WIN_DEFS_H */
 
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
 
7
8
9
 
 
10
11
12
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
19
20
21
22
23
24
@@ -7,32 +7,18 @@
 #include <shlwapi.h>     -STDMETHODIMP CShellExt::GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, - int *pIndex, DWORD *pdwFlags) +STDMETHODIMP CShellExt::GetOverlayInfo( + LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags)  { + TDEBUG_TRACE("CShellExt::GetOverlayInfo: myTortoiseClass = " << myTortoiseClass); + // icons are determined by TortoiseOverlays shim   *pIndex = 0; - *pdwFlags = ISIOI_ICONFILE; - - // get installation path - std::string dir = GetTHgProgRoot(); - if (dir.empty()) - { - TDEBUG_TRACE("GetOverlayInfo: THG root is empty"); - wcsncpy(pwszIconFile, L"", cchMax); - return S_OK; - } - - // find icon per overlay type - std::wstring dirWide = MultibyteToWide(dir); - wcsncpy(pwszIconFile, dirWide.c_str(), cchMax); - cchMax -= static_cast<int>(dirWide.size()) + 1; - - std::string path = WideToMultibyte(pwszIconFile); - TDEBUG_TRACE("GetOverlayInfo: icon path = " << path); - + *pdwFlags = 0; + *pwszIconFile = 0;   return S_OK;  }   +  STDMETHODIMP CShellExt::GetPriority(int *pPriority)  {   *pPriority = 1;
 
8
9
10
11
12
13
14
 
8
9
10
 
11
12
13
@@ -8,7 +8,6 @@
  ContextMenu.o \   IconOverlay.o \   ShellExt.o \ - ShellUtils2.o \   StringUtils.o \   dirstate.o \   Winstat64.o \
 
8
9
10
11
12
13
14
 
8
9
10
 
11
12
13
@@ -8,7 +8,6 @@
  ContextMenu.obj \   IconOverlay.obj \   ShellExt.obj \ - ShellUtils2.obj \   StringUtils.obj \   dirstate.obj \   Winstat64.obj \
Change 1 of 1 Show Entire File win32/​shellext/​Registry.cpp Stacked
 
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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,799 +0,0 @@
- - -//#include "stdafx.h" -#include <windows.h> -#include <winreg.h> -#include "Registry.h" - -#define CLASS_NAME_LENGTH 255 - -/* IMPORTANT NOTES ABOUT CREGISTRY: - - CRegistry never keeps a key open past the end of a function call. - This is incase the application crashes before the next call to close - the registry - - INCLUDE FILES - "winreg.h" and "afxdisp.h" must be included in "stdafx.h" - - KEY NAMES: - Key names must not begin with a \ and only absolute strings are accepted - -*/ - - - -CRegistry::CRegistry() -{ - m_hRootKey = HKEY_CURRENT_USER; - m_bLazyWrite = TRUE; - m_nLastError = ERROR_SUCCESS; -} - -CRegistry::~CRegistry() -{ - ClearKey(); -} - - -BOOL CRegistry::ClearKey() -{ - /* Call CloseKey to write the current key to the registry and close the - key. An application should not keep keys open any longer than necessary. - Calling CloseKey when there is no current key has no effect.*/ - - m_strCurrentPath.Empty(); - m_hRootKey = HKEY_CURRENT_USER; - m_bLazyWrite = TRUE; - return TRUE; -} - - - -BOOL CRegistry::SetRootKey(HKEY hRootKey) -{ - // sets the root key - // make sure to set it to a valid key - if (hRootKey != HKEY_CLASSES_ROOT && - hRootKey != HKEY_CURRENT_USER && - hRootKey != HKEY_LOCAL_MACHINE && - hRootKey != HKEY_USERS) return FALSE; - - m_hRootKey = hRootKey; - return TRUE; -} - - -BOOL CRegistry::CreateKey(CString strKey) -{ - /* Use CreateKey to add a new key to the registry. - Key is the name of the key to create. Key must be - an absolute name. An absolute key - begins with a backslash (\) and is a subkey of - the root key. */ - - ASSERT(strKey[0] != '\\'); - HKEY hKey; - - DWORD dwDisposition = 0; - - if (::RegCreateKeyEx(m_hRootKey, LPCTSTR(strKey), 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, - &dwDisposition) != ERROR_SUCCESS) return FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - m_strCurrentPath = strKey; - return TRUE; -} - - -BOOL CRegistry::DeleteKey(CString strKey) -{ - /* Call DeleteKey to remove a specified key and its associated data, - if any, from the registry. Returns FALSE is there are subkeys - Subkeys must be explicitly deleted by separate calls to DeleteKey. - DeleteKey returns True if key deletion is successful. On error, - DeleteKey returns False. */ - - // need to open the key first with RegOpenKeyEx - ASSERT(FALSE); // not yet implemented - ASSERT(strKey[0] != '\\'); - - if (!KeyExists(strKey)) return TRUE; - if (::RegDeleteKey(m_hRootKey, strKey) != ERROR_SUCCESS) return FALSE; - return TRUE; -} - - - -BOOL CRegistry::DeleteValue(CString strName) -{ - /* Call DeleteValue to remove a specific data value - associated with the current key. Name is string - containing the name of the value to delete. Keys can contain - multiple data values, and every value associated with a key - has a unique name. */ - - ASSERT(m_strCurrentPath.GetLength() > 0); - HKEY hKey; - LONG lResult; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_SET_VALUE, &hKey) != ERROR_SUCCESS) return FALSE; - - lResult = ::RegDeleteValue(hKey, LPCTSTR(strName)); - ::RegCloseKey(hKey); - - if (lResult == ERROR_SUCCESS) return TRUE; - return FALSE; -} - - -int CRegistry::GetDataSize(CString strValueName) -{ - /* Call GetDataSize to determine the size, in bytes, of - a data value associated with the current key. ValueName - is a string containing the name of the data value to query. - On success, GetDataSize returns the size of the data value. - On failure, GetDataSize returns -1. */ - - HKEY hKey; - ASSERT(m_strCurrentPath.GetLength() > 0); - LONG lResult; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) return -1; - - DWORD dwSize = 1; - lResult = ::RegQueryValueEx(hKey, LPCTSTR(strValueName), - NULL, NULL, NULL, &dwSize); - ::RegCloseKey(hKey); - - if (lResult != ERROR_SUCCESS) return -1; - return (int)dwSize; -} - -DWORD CRegistry::GetDataType(CString strValueName) -{ - HKEY hKey; - ASSERT(m_strCurrentPath.GetLength() > 0); - - m_nLastError = ::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_QUERY_VALUE, &hKey); - - if (m_nLastError != ERROR_SUCCESS) return 0; - - DWORD dwType = 1; - m_nLastError = ::RegQueryValueEx(hKey, LPCTSTR(strValueName), - NULL, &dwType, NULL, NULL); - ::RegCloseKey(hKey); - - if (m_nLastError == ERROR_SUCCESS) return dwType; - - return 0; -} - - - -int CRegistry::GetSubKeyCount() -{ - /* Call this function to determine the number of subkeys. - the function returns -1 on error */ - HKEY hKey; - ASSERT(m_strCurrentPath.GetLength() > 0); - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) return -1; - - LONG lResult; - DWORD dwSubKeyCount, dwValueCount, dwClassNameLength, - dwMaxSubKeyName, dwMaxValueName, dwMaxValueLength; - FILETIME ftLastWritten; - - _TCHAR szClassBuffer[CLASS_NAME_LENGTH]; - - dwClassNameLength = CLASS_NAME_LENGTH; - lResult = ::RegQueryInfoKey(hKey, szClassBuffer, &dwClassNameLength, - NULL, &dwSubKeyCount, &dwMaxSubKeyName, NULL, &dwValueCount, - &dwMaxValueName, &dwMaxValueLength, NULL, &ftLastWritten); - - ::RegCloseKey(hKey); - if (lResult != ERROR_SUCCESS) return -1; - - return (int)dwSubKeyCount; -} - - -int CRegistry::GetValueCount() -{ - /* Call this function to determine the number of subkeys. - the function returns -1 on error */ - HKEY hKey; - ASSERT(m_strCurrentPath.GetLength() > 0); - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) return -1; - - LONG lResult; - DWORD dwSubKeyCount, dwValueCount, dwClassNameLength, - dwMaxSubKeyName, dwMaxValueName, dwMaxValueLength; - FILETIME ftLastWritten; - - _TCHAR szClassBuffer[CLASS_NAME_LENGTH]; - - dwClassNameLength = CLASS_NAME_LENGTH; - lResult = ::RegQueryInfoKey(hKey, szClassBuffer, &dwClassNameLength, - NULL, &dwSubKeyCount, &dwMaxSubKeyName, NULL, &dwValueCount, - &dwMaxValueName, &dwMaxValueLength, NULL, &ftLastWritten); - - ::RegCloseKey(hKey); - if (lResult != ERROR_SUCCESS) return -1; - - return (int)dwValueCount; -} - - -BOOL CRegistry::KeyExists(CString strKey, HKEY hRootKey) -{ - /* Call KeyExists to determine if a key of a specified name exists. - Key is the name of the key for which to search. */ - - ASSERT(strKey[0] != '\\'); - HKEY hKey; - - if (hRootKey == NULL) hRootKey = m_hRootKey; - - LONG lResult = ::RegOpenKeyEx(hRootKey, LPCTSTR(strKey), 0, - KEY_ALL_ACCESS, &hKey); - ::RegCloseKey(hKey); - if (lResult == ERROR_SUCCESS) return TRUE; - return FALSE; -} - -BOOL CRegistry::SetKey(CString strKey, BOOL bCanCreate) -{ - /* Call SetKey to make a specified key the current key. Key is the - name of the key to open. If Key is null, the CurrentKey property - is set to the key specified by the RootKey property. - - CanCreate specifies whether to create the specified key if it does - not exist. If CanCreate is True, the key is created if necessary. - - Key is opened or created with the security access value KEY_ALL_ACCESS. - OpenKey only creates non-volatile keys, A non-volatile key is stored in - the registry and is preserved when the system is restarted. - - OpenKey returns True if the key is successfully opened or created */ - - ASSERT(strKey[0] != '\\'); - HKEY hKey; - - - // close the current key if it is open - if (strKey.GetLength() == 0) - { - m_strCurrentPath.Empty(); - return TRUE; - } - - DWORD dwDisposition; - if (bCanCreate) // open the key with RegCreateKeyEx - { - if (::RegCreateKeyEx(m_hRootKey, LPCTSTR(strKey), 0, NULL, - REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, - &dwDisposition) != ERROR_SUCCESS) return FALSE; - m_strCurrentPath = strKey; - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return TRUE; - } - - // otherwise, open the key without creating - // open key requires no initial slash - m_nLastError = ::RegOpenKeyEx(m_hRootKey, LPCTSTR(strKey), 0, - KEY_ALL_ACCESS, &hKey); - if (m_nLastError != ERROR_SUCCESS) return FALSE; - m_strCurrentPath = strKey; - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return TRUE; -} - - -BOOL CRegistry::ValueExists(CString strName) -{ - /* Call ValueExists to determine if a particular key exists in - the registry. Calling Value Exists is especially useful before - calling other TRegistry methods that operate only on existing keys. - - Name is the name of the data value for which to check. - ValueExists returns True if a match if found, False otherwise. */ - - HKEY hKey; - LONG lResult; - ASSERT(m_strCurrentPath.GetLength() > 0); - - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_ALL_ACCESS, &hKey) != ERROR_SUCCESS) return FALSE; - - lResult = ::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - NULL, NULL, NULL); - ::RegCloseKey(hKey); - - if (lResult == ERROR_SUCCESS) return TRUE; - return FALSE; -} - - -void CRegistry::RenameValue(CString strOldName, CString strNewName) -{ - /* Call RenameValue to change the name of a data value associated - with the current key. OldName is a string containing the current - name of the data value. NewName is a string containing the replacement - name for the data value. - - If OldName is the name of an existing data value for the current key, - and NewName is not the name of an existing data value for the current - key, RenameValue changes the data value name as specified. Otherwise - the current name remains unchanged. - */ - ASSERT(FALSE); // functionality not yet implemented -} - - - - -COleDateTime CRegistry::ReadDateTime(CString strName, COleDateTime dtDefault) -{ - /* Call ReadDate to read a date value from a specified data value - associated with the current key. Name is the name of the data value to read. - If successful, ReadDate returns a Delphi TDateTime value. The integral part - of a TDateTime value is the number of days that have passed since 12/30/1899. - The fractional part of a TDateTime value is the time of day. - On error, an exception is raised, and the value returned by this function - should be discarded. */ - - DWORD dwType = REG_BINARY; - COleDateTime dt; - DWORD dwSize = sizeof(dt); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return dtDefault; - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&dt, &dwSize) != ERROR_SUCCESS) dt = dtDefault; - ::RegCloseKey(hKey); - return dt; -} - - -double CRegistry::ReadFloat(CString strName, double fDefault) -{ - /* Call ReadFloat to read a float value from a specified - data value associated with the current key. Name is the name - of the data value to read. - - If successful, ReadFloat returns a double value. - On error, an exception is raised, and the value returned by - this function should be discarded. */ - - DWORD dwType = REG_BINARY; - double d; - DWORD dwSize = sizeof(d); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return fDefault; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&d, &dwSize) != ERROR_SUCCESS) d = fDefault; - ::RegCloseKey(hKey); - return d; -} - -CString CRegistry::ReadString(CString strName, CString strDefault) -{ - DWORD dwType = REG_SZ; - DWORD dwSize = 255; - BOOL bSuccess = TRUE; - _TCHAR sz[255]; - HKEY hKey; - - - ASSERT(m_strCurrentPath.GetLength() > 0); - - // make sure it is the proper type - dwType = GetDataType(strName); - - if (dwType != REG_SZ && dwType != REG_EXPAND_SZ) - { - return strDefault; - } - - m_nLastError = ::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey); - if (m_nLastError != ERROR_SUCCESS) return strDefault; - - m_nLastError = ::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)sz, &dwSize); - if (m_nLastError != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - - if (!bSuccess) return strDefault; - return CString((LPCTSTR)sz); -} - -DWORD CRegistry::ReadDword(CString strName, DWORD dwDefault) -{ - DWORD dwType = REG_DWORD; - DWORD dw; - DWORD dwSize = sizeof(dw); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return dwDefault; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&dw, &dwSize) != ERROR_SUCCESS) dw = dwDefault; - ::RegCloseKey(hKey); - return dw; -} - - - -int CRegistry::ReadInt(CString strName, int nDefault) -{ - DWORD dwType = REG_BINARY; - int n; - DWORD dwSize = sizeof(n); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return nDefault; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&n, &dwSize) != ERROR_SUCCESS) n = nDefault; - ::RegCloseKey(hKey); - return n; -} - -BOOL CRegistry::ReadBool(CString strName, BOOL bDefault) -{ - DWORD dwType = REG_BINARY; - BOOL b; - DWORD dwSize = sizeof(b); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return bDefault; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&b, &dwSize) != ERROR_SUCCESS) b = bDefault; - ::RegCloseKey(hKey); - return b; -} - - -COLORREF CRegistry::ReadColor(CString strName, COLORREF rgbDefault) -{ - DWORD dwType = REG_BINARY; - COLORREF rgb; - DWORD dwSize = sizeof(rgb); - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return rgbDefault; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&rgb, &dwSize) != ERROR_SUCCESS) rgb = rgbDefault; - ::RegCloseKey(hKey); - return rgb; -} - -BOOL CRegistry::ReadFont(CString strName, CFont* pFont) -{ - DWORD dwType = REG_BINARY; - DWORD dwSize = sizeof(LOGFONT); - BOOL bSuccess = TRUE; - HKEY hKey; - LOGFONT lf; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)&lf, &dwSize) != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - if (bSuccess) - { - pFont->Detach(); - pFont->CreateFontIndirect(&lf); - } - return bSuccess; -} - - -BOOL CRegistry::ReadPoint(CString strName, CPoint* pPoint) -{ - DWORD dwType = REG_BINARY; - DWORD dwSize = sizeof(CPoint); - BOOL bSuccess = TRUE; - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)pPoint, &dwSize) != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::ReadSize(CString strName, CSize* pSize) -{ - DWORD dwType = REG_BINARY; - DWORD dwSize = sizeof(CSize); - BOOL bSuccess = TRUE; - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)pSize, &dwSize) != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::ReadRect(CString strName, CRect* pRect) -{ - DWORD dwType = REG_BINARY; - DWORD dwSize = sizeof(CRect); - BOOL bSuccess = TRUE; - HKEY hKey; - - ASSERT(m_strCurrentPath.GetLength() > 0); - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_READ, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegQueryValueEx(hKey, LPCTSTR(strName), NULL, - &dwType, (LPBYTE)pRect, &dwSize) != ERROR_SUCCESS) bSuccess = FALSE; - ::RegCloseKey(hKey); - return bSuccess; -} - - - - -BOOL CRegistry::WriteBool(CString strName, BOOL bValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&bValue, sizeof(bValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteDateTime(CString strName, COleDateTime dtValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&dtValue, sizeof(dtValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WriteString(CString strName, CString strValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - _TCHAR sz[255]; - - if (strValue.GetLength() > 254) return FALSE; - -#ifdef _UNICODE - wstrcpy(sz, LPCTSTR(strValue)); -#else - strcpy(sz, LPCTSTR(strValue)); -#endif - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - -#ifdef _UNICODE - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_SZ, (LPBYTE)sz, wstrlen(sz) + 1) - != ERROR_SUCCESS) bSuccess = FALSE; -#else - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_SZ, (LPBYTE)sz, strlen(sz) + 1) - != ERROR_SUCCESS) bSuccess = FALSE; -#endif - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WriteFloat(CString strName, double fValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&fValue, sizeof(fValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteInt(CString strName, int nValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&nValue, sizeof(nValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteDword(CString strName, DWORD dwValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&dwValue, sizeof(dwValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteColor(CString strName, COLORREF rgbValue) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&rgbValue, sizeof(rgbValue)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WriteFont(CString strName, CFont* pFont) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - LOGFONT lf; - pFont->GetLogFont(&lf); - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)&lf, sizeof(lf)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WritePoint(CString strName, CPoint* pPoint) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)pPoint, sizeof(CPoint)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - - -BOOL CRegistry::WriteSize(CString strName, CSize* pSize) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)pSize, sizeof(CSize)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} - -BOOL CRegistry::WriteRect(CString strName, CRect* pRect) -{ - ASSERT(m_strCurrentPath.GetLength() > 0); - BOOL bSuccess = TRUE; - HKEY hKey; - - if (::RegOpenKeyEx(m_hRootKey, LPCTSTR(m_strCurrentPath), 0, - KEY_WRITE, &hKey) != ERROR_SUCCESS) return FALSE; - - if (::RegSetValueEx(hKey, LPCTSTR(strName), 0, - REG_BINARY, (LPBYTE)pRect, sizeof(CRect)) - != ERROR_SUCCESS) bSuccess = FALSE; - - if (!m_bLazyWrite) ::RegFlushKey(hKey); - ::RegCloseKey(hKey); - return bSuccess; -} -
Change 1 of 1 Show Entire File win32/​shellext/​Registry.h Stacked
 
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,77 +0,0 @@
- - -#ifndef __REGISTRY_H__ -#define __REGISTRY_H__ - -#include <string> -typedef std::string CString; - -class CRegistry -{ -public: - CRegistry(); - ~CRegistry(); - -int m_nLastError; - -// CRegistry properties -protected: - HKEY m_hRootKey; - BOOL m_bLazyWrite; - CString m_strCurrentPath; - -public: - inline BOOL PathIsValid() { - return (m_strCurrentPath.GetLength() > 0); } - inline CString GetCurrentPath() { - return m_strCurrentPath; } - inline HKEY GetRootKey() { - return m_hRootKey; } - - -//CRegistry methods -public: - BOOL ClearKey(); - BOOL SetRootKey(HKEY hRootKey); - BOOL CreateKey(CString strKey); - BOOL DeleteKey(CString strKey); - BOOL DeleteValue(CString strName); - int GetDataSize(CString strValueName); - DWORD GetDataType(CString strValueName); - int GetSubKeyCount(); - int GetValueCount(); - BOOL KeyExists(CString strKey, HKEY hRootKey = NULL); - BOOL SetKey(CString strKey, BOOL bCanCreate); - BOOL ValueExists(CString strName); - void RenameValue(CString strOldName, CString strNewName); - - // data reading functions - COleDateTime ReadDateTime(CString strName, COleDateTime dtDefault); - double ReadFloat(CString strName, double fDefault); - CString ReadString(CString strName, CString strDefault); - int ReadInt(CString strName, int nDefault); - BOOL ReadBool(CString strName, BOOL bDefault); - COLORREF ReadColor(CString strName, COLORREF rgbDefault); - BOOL ReadFont(CString strName, CFont* pFont); - BOOL ReadPoint(CString strName, CPoint* pPoint); - BOOL ReadSize(CString strName, CSize* pSize); - BOOL ReadRect(CString strName, CRect* pRect); - DWORD ReadDword(CString strName, DWORD dwDefault); - - // data writing functions - BOOL WriteBool(CString strName, BOOL bValue); - BOOL WriteDateTime(CString strName, COleDateTime dtValue); - BOOL WriteString(CString strName, CString strValue); - BOOL WriteFloat(CString strName, double fValue); - BOOL WriteInt(CString strName, int nValue); - BOOL WriteColor(CString strName, COLORREF rgbValue); - BOOL WriteFont(CString strName, CFont* pFont); - BOOL WritePoint(CString strName, CPoint* pPoint); - BOOL WriteSize(CString strName, CSize* pSize); - BOOL WriteRect(CString strName, CRect* pRect); - BOOL WriteDword(CString strName, DWORD dwValue); - -};// end of CRegistry class definition - - -#endif \ No newline at end of file
 
1
2
3
4
5
6
7
 
16
17
18
19
20
 
 
21
22
 
23
24
25
 
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
 
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
 
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
 
195
196
197
 
198
199
200
 
205
206
207
 
208
209
210
211
212
213
214
 
 
215
216
217
218
219
220
221
 
222
223
224
 
244
245
246
247
 
248
249
250
251
252
253
 
254
255
256
257
 
 
258
259
260
261
262
263
264
 
 
265
266
267
 
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
 
 
293
294
295
 
302
303
304
305
306
307
308
 
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
 
395
396
397
398
399
 
1
2
3
 
4
5
6
 
15
16
17
 
 
18
19
20
 
21
22
23
24
 
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
 
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
 
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
 
206
207
208
209
210
211
212
 
217
218
219
220
221
222
223
224
225
 
 
226
227
228
229
230
231
232
233
 
234
235
236
237
 
257
258
259
 
260
261
262
263
264
265
 
266
267
268
 
 
269
270
271
272
273
274
275
 
 
276
277
278
279
280
 
285
286
287
 
 
 
 
 
 
 
 
 
 
 
 
 
288
 
 
 
 
289
290
291
292
293
 
300
301
302
 
303
304
305
 
334
335
336
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
337
338
339
 
346
347
348
 
 
@@ -1,7 +1,6 @@
 #include "stdafx.h"  #include "ShellExt.h"  #include "TortoiseUtils.h" -#include "ShellUtils.h"  #include "StringUtils.h"  #include <olectl.h>   @@ -16,10 +15,10 @@
 DEFINE_GUID(CLSID_TortoiseHg5, 0xb456dba5L, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e);  DEFINE_GUID(CLSID_TortoiseHg6, 0xb456dba6L, 0x7bf4, 0x478c, 0x93, 0x7a, 0x5, 0x13, 0xc, 0x2c, 0x21, 0x2e);   -UINT g_cRefThisDll = 0; -HINSTANCE g_hmodThisDll = NULL; +UINT g_cRefThisDll = 0; +HINSTANCE g_hmodThisDll = NULL;   -HMENU hSubMenu = 0; +HMENU hSubMenu = 0;    CRITICAL_SECTION g_critical_section;   @@ -32,80 +31,88 @@
  LPTSTR lpszData;  } REGSTRUCT, *LPREGSTRUCT;   -VOID _LoadResources(); -VOID _UnloadResources(); + +VOID _LoadResources(); +VOID _UnloadResources(); +    extern "C"  int APIENTRY DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)  { - TDEBUG_TRACE("DllMain"); -   if (dwReason == DLL_PROCESS_ATTACH) - { + {   TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH");   g_hmodThisDll = hInstance;   ::InitializeCriticalSection(&g_critical_section); - _LoadResources(); - } - else if (dwReason == DLL_PROCESS_DETACH) + _LoadResources(); + } + else if (dwReason == DLL_PROCESS_DETACH)   {   TDEBUG_TRACE("DllMain: DLL_PROCESS_ATTACH");   ::DeleteCriticalSection(&g_critical_section); - _UnloadResources(); + _UnloadResources();   }     return 1;  }   +  STDAPI DllCanUnloadNow(void)  {   TDEBUG_TRACE("DllCanUnloadNow");   return (g_cRefThisDll == 0 ? S_OK : S_FALSE);  }   +  STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppvOut)  { - LPWSTR pwszShellExt; - StringFromIID(rclsid, &pwszShellExt); + LPWSTR pwszShellExt; + StringFromIID(rclsid, &pwszShellExt);   TDEBUG_TRACE("DllGetClassObject clsid = " << WideToMultibyte(pwszShellExt));   *ppvOut = NULL;     if (IsEqualIID(rclsid, CLSID_TortoiseHg0))   { - CDllRegSxClassFactory *pcf = new CDllRegSxClassFactory(TORTOISE_OLE_UNCHANGED); + CDllRegSxClassFactory *pcf = + new CDllRegSxClassFactory(TORTOISE_OLE_UNCHANGED);   TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg0");   return pcf->QueryInterface(riid, ppvOut);   }   else if (IsEqualIID(rclsid, CLSID_TortoiseHg1))   { - CDllRegSxClassFactory *pcf = new CDllRegSxClassFactory(TORTOISE_OLE_ADDED); + CDllRegSxClassFactory *pcf = + new CDllRegSxClassFactory(TORTOISE_OLE_ADDED);   TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg1");   return pcf->QueryInterface(riid, ppvOut);   }   else if (IsEqualIID(rclsid, CLSID_TortoiseHg2))   { - CDllRegSxClassFactory *pcf = new CDllRegSxClassFactory(TORTOISE_OLE_MODIFIED); + CDllRegSxClassFactory *pcf = + new CDllRegSxClassFactory(TORTOISE_OLE_MODIFIED);   TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg2");   return pcf->QueryInterface(riid, ppvOut);   }   else if (IsEqualIID(rclsid, CLSID_TortoiseHg6))   { - CDllRegSxClassFactory *pcf = new CDllRegSxClassFactory(TORTOISE_OLE_NOTINREPO); + CDllRegSxClassFactory *pcf = + new CDllRegSxClassFactory(TORTOISE_OLE_NOTINREPO);   TDEBUG_TRACE("DllGetClassObject clsname = " << "CLSID_TortoiseHg6");   return pcf->QueryInterface(riid, ppvOut);   } - +   return CLASS_E_CLASSNOTAVAILABLE;  }   +  VOID _LoadResources(VOID)  {  }   +  VOID _UnloadResources(VOID)  { - if (hSubMenu) - DestroyMenu(hSubMenu); + if (hSubMenu) + DestroyMenu(hSubMenu);  }     @@ -114,45 +121,47 @@
  return &g_critical_section;  }   +  CDllRegSxClassFactory::CDllRegSxClassFactory(TortoiseOLEClass classToMake)  {   ThgCriticalSection cs(GetCriticalSection());   m_cRef = 0L; - g_cRefThisDll++; + g_cRefThisDll++;   myclassToMake = classToMake;  } - -CDllRegSxClassFactory::~CDllRegSxClassFactory() + + +CDllRegSxClassFactory::~CDllRegSxClassFactory()  {   ThgCriticalSection cs(GetCriticalSection());   g_cRefThisDll--;  }   -STDMETHODIMP -CDllRegSxClassFactory::QueryInterface(REFIID riid, LPVOID FAR *ppv) + +STDMETHODIMP CDllRegSxClassFactory::QueryInterface( + REFIID riid, LPVOID FAR* ppv)  {   *ppv = NULL;   - if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory)) + if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_IClassFactory))   { - *ppv = (LPCLASSFACTORY)this; + *ppv = (LPCLASSFACTORY) this;   AddRef(); -   return NOERROR;   }     return E_NOINTERFACE; -} +}   -STDMETHODIMP_(ULONG) -CDllRegSxClassFactory::AddRef() + +STDMETHODIMP_(ULONG) CDllRegSxClassFactory::AddRef()  {   ThgCriticalSection cs(GetCriticalSection());   return ++m_cRef;  }   -STDMETHODIMP_(ULONG) -CDllRegSxClassFactory::Release() + +STDMETHODIMP_(ULONG) CDllRegSxClassFactory::Release()  {   ThgCriticalSection cs(GetCriticalSection());   if (--m_cRef) @@ -162,29 +171,31 @@
  return 0L;  }   -STDMETHODIMP -CDllRegSxClassFactory::CreateInstance(LPUNKNOWN pUnkOuter, REFIID riid, LPVOID *ppvObj) + +STDMETHODIMP CDllRegSxClassFactory::CreateInstance( + LPUNKNOWN pUnkOuter, REFIID riid, LPVOID* ppvObj)  {   *ppvObj = NULL;     if (pUnkOuter) - return CLASS_E_NOAGGREGATION; + return CLASS_E_NOAGGREGATION;     LPCSHELLEXT pShellExt = new CShellExt(myclassToMake);   if (NULL == pShellExt) - return E_OUTOFMEMORY; + return E_OUTOFMEMORY;     return pShellExt->QueryInterface(riid, ppvObj);  }   -STDMETHODIMP -CDllRegSxClassFactory::LockServer(BOOL fLock) + +STDMETHODIMP CDllRegSxClassFactory::LockServer(BOOL fLock)  {   return NOERROR;  }   +  CShellExt::CShellExt(TortoiseOLEClass tortoiseClass) - : m_ppszFileUserClickedOn(0) + : m_ppszFileUserClickedOn(0)  {   ThgCriticalSection cs(GetCriticalSection());   @@ -195,6 +206,7 @@
  g_cRefThisDll++;  }   +  CShellExt::~CShellExt()  {   ThgCriticalSection cs(GetCriticalSection()); @@ -205,20 +217,21 @@
  g_cRefThisDll--;  }   +  LPCRITICAL_SECTION CShellExt::GetCriticalSection()  {   return &g_critical_section;  }   -STDMETHODIMP -CShellExt::QueryInterface(REFIID riid, LPVOID FAR *ppv) + +STDMETHODIMP CShellExt::QueryInterface(REFIID riid, LPVOID FAR* ppv)  {   std::string clsname = "UNKNOWN CLSID";     *ppv = NULL;   if (IsEqualIID(riid, IID_IShellExtInit) || IsEqualIID(riid, IID_IUnknown))   { - *ppv = (LPSHELLEXTINIT)this; + *ppv = (LPSHELLEXTINIT)this;   clsname = "IID_IShellExtInit";   }   else if (IsEqualIID(riid, IID_IContextMenu)) @@ -244,24 +257,24 @@
    TDEBUG_TRACE("CShellExt::QueryInterface: " << clsname);   - if(*ppv) + if (*ppv)   {   AddRef();   return NOERROR;   }   - return E_NOINTERFACE; + return E_NOINTERFACE;  }   -STDMETHODIMP_(ULONG) -CShellExt::AddRef() + +STDMETHODIMP_(ULONG) CShellExt::AddRef()  {   ThgCriticalSection cs(GetCriticalSection());   return ++m_cRef;  }   -STDMETHODIMP_(ULONG) -CShellExt::Release() + +STDMETHODIMP_(ULONG) CShellExt::Release()  {   ThgCriticalSection cs(GetCriticalSection());   @@ -272,24 +285,9 @@
  return 0L;  }   -#if 0 -STDMETHODIMP -CShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) -{ - if (m_pDataObj) - m_pDataObj->Release(); - if (pDataObj) - { - m_pDataObj = pDataObj; - pDataObj->AddRef(); - } - return NOERROR; -}   -#else - -STDMETHODIMP -CShellExt::Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey) +STDMETHODIMP CShellExt::Initialize( + LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hRegKey)  {   TCHAR name[MAX_PATH+1];   @@ -302,7 +300,6 @@
    if (pDataObj)   { -#if 1   FORMATETC fmt = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };   STGMEDIUM stg = { TYMED_HGLOBAL };   if (SUCCEEDED(pDataObj->GetData(&fmt, &stg)) && stg.hGlobal) @@ -337,52 +334,6 @@
  {   TDEBUG_TRACE(" pDataObj->GetData failed");   } - -#else - - STGMEDIUM medium; - FORMATETC fmte = { RegisterClipboardFormat(CFSTR_SHELLIDLIST), - NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL }; - HRESULT hres = pDataObj->GetData(&fmte, &medium); - - if (SUCCEEDED(hres) && medium.hGlobal) - { - // Enumerate PIDLs which the user has selected - CIDA* cida = (CIDA*) GlobalLock(medium.hGlobal); - LPCITEMIDLIST parentFolder = GetPIDLFolder(cida); - TDEBUG_TRACE("Parent folder: " << GetPathFromIDList(parentFolder)); - int count = cida->cidl; - TDEBUG_TRACE("Selected items: " << count); - for (int i = 0; i < count; ++i) - { - LPCITEMIDLIST child = GetPIDLItem(cida, i); - LPITEMIDLIST absolute = AppendPIDL(parentFolder, child); - std::string name = GetPathFromIDList(absolute); - TDEBUG_TRACE("Processing " << GetPathFromIDList(absolute)); - if (IsShortcut(absolute)) - { - TDEBUG_TRACE("IsShortCut " << name); - LPITEMIDLIST target = GetShortcutTarget(absolute); - ItemListFree(absolute); - absolute = target; - name = GetPathFromIDList(target); - } - - name = GetPathFromIDList(absolute); - TDEBUG_TRACE("myFiles pusing " << name); - myFiles.push_back(name); - - ItemListFree(absolute); - } - - GlobalUnlock(medium.hGlobal); - if (medium.pUnkForRelease) - { - IUnknown* relInterface = (IUnknown*) medium.pUnkForRelease; - relInterface->Release(); - } - } -#endif   }     // if a directory background @@ -395,5 +346,3 @@
    return NOERROR;  } - -#endif
 
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
 
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
@@ -15,80 +15,80 @@
  TORTOISE_OLE_NOTINREPO,  };   -// -// Factory -// -class CDllRegSxClassFactory : public IClassFactory + +class CDllRegSxClassFactory: public IClassFactory  {   protected: - ULONG m_cRef; + ULONG m_cRef;   TortoiseOLEClass myclassToMake;     public:   CDllRegSxClassFactory(TortoiseOLEClass);   ~CDllRegSxClassFactory();   - public:   static LPCRITICAL_SECTION GetCriticalSection();   - STDMETHODIMP QueryInterface(REFIID, LPVOID FAR *); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); + STDMETHODIMP QueryInterface(REFIID, LPVOID FAR*); + STDMETHODIMP_(ULONG) AddRef(); + STDMETHODIMP_(ULONG) Release();   - STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR *); - STDMETHODIMP LockServer(BOOL); + STDMETHODIMP CreateInstance(LPUNKNOWN, REFIID, LPVOID FAR*); + STDMETHODIMP LockServer(BOOL);  };   -typedef CDllRegSxClassFactory *LPCSHELLEXTCLASSFACTORY; +typedef CDllRegSxClassFactory* LPCSHELLEXTCLASSFACTORY;   -// -// Shell extensions -// -class CShellExt : - public - IContextMenu3, - IShellIconOverlayIdentifier, - IShellExtInit + +class CShellExt: + public IContextMenu3, IShellIconOverlayIdentifier, IShellExtInit  { - TortoiseOLEClass myTortoiseClass; + TortoiseOLEClass myTortoiseClass;     protected: - ULONG m_cRef; - LPDATAOBJECT m_pDataObj; + ULONG m_cRef; + LPDATAOBJECT m_pDataObj;   - LPTSTR *m_ppszFileUserClickedOn; // [MAX_PATH] + LPTSTR* m_ppszFileUserClickedOn; // [MAX_PATH]   std::vector<std::string> myFiles; - std::string myFolder; - void CShellExt::DoHgtk(const std::string &); - + std::string myFolder; + + void CShellExt::DoHgtk(const std::string&); +   public:   static LPCRITICAL_SECTION GetCriticalSection();     CShellExt(TortoiseOLEClass);   ~CShellExt();   - // IUnknown - STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR *ppv); - STDMETHODIMP_(ULONG) AddRef(); - STDMETHODIMP_(ULONG) Release(); + // IUnknown + STDMETHODIMP QueryInterface(REFIID riid, LPVOID FAR *ppv); + STDMETHODIMP_(ULONG) AddRef(); + STDMETHODIMP_(ULONG) Release();   - // IContextMenu3 - STDMETHODIMP QueryContextMenu(HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags); - STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi); - STDMETHODIMP GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT FAR *reserved, LPSTR pszName, UINT cchMax); - STDMETHODIMP HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam); - STDMETHODIMP HandleMenuMsg2(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult); + // IContextMenu3 + STDMETHODIMP QueryContextMenu( + HMENU hMenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, + UINT uFlags); + STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi); + STDMETHODIMP GetCommandString( + UINT_PTR idCmd, UINT uFlags, UINT FAR* reserved,LPSTR pszName, + UINT cchMax); + STDMETHODIMP HandleMenuMsg(UINT uMsg, WPARAM wParam, LPARAM lParam); + STDMETHODIMP HandleMenuMsg2( + UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pResult);     // IShellIconOverlayIdentifier - STDMETHODIMP GetOverlayInfo(LPWSTR pwszIconFile, int cchMax, int *pIndex, DWORD *pdwFlags); - STDMETHODIMP GetPriority(int *pPriority); - STDMETHODIMP IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib); + STDMETHODIMP GetOverlayInfo( + LPWSTR pwszIconFile, int cchMax, int* pIndex, DWORD* pdwFlags); + STDMETHODIMP GetPriority(int* pPriority); + STDMETHODIMP IsMemberOf(LPCWSTR pwszPath, DWORD dwAttrib);   - // IShellExtInit - STDMETHODIMP Initialize(LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID); + // IShellExtInit + STDMETHODIMP Initialize( + LPCITEMIDLIST pIDFolder, LPDATAOBJECT pDataObj, HKEY hKeyID);   };   -typedef CShellExt *LPCSHELLEXT; +typedef CShellExt* LPCSHELLEXT;      class ThgCriticalSection
Change 1 of 1 Show Entire File win32/​shellext/​ShellUtils.cpp Stacked
 
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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,793 +0,0 @@
-// TortoiseCVS - a Windows shell extension for easy version control - -// Copyright (C) 2001 - Francis Irving -// <francis@flourish.org> - May 2001 - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -#include "StdAfx.h" - -//#include "PathUtils.h" -#include "StringUtils.h" -//#include "UnicodeStrings.h" -//#include "TortoiseRegistry.h" -//#include "Translate.h" -#include <windows.h> -#include <map> -#include <sstream> - -// TODO: Put shlwapi.h in mingw32 -#ifndef __GNUC__ -#include <shlwapi.h> - -#else - -#ifndef DLLVERSIONINFO -typedef struct _DllVersionInfo -{ - DWORD cbSize; - DWORD dwMajorVersion; - DWORD dwMinorVersion; - DWORD dwBuildNumber; - DWORD dwPlatformID; -} DLLVERSIONINFO; -#endif - -#ifndef DLLGETVERSIONPROC -typedef int (FAR WINAPI *DLLGETVERSIONPROC) (DLLVERSIONINFO *); -#endif - -#endif - -#include "ShellUtils.h" -//#include "TortoiseException.h" -//#include "TortoiseUtils.h" -//#include "ProcessUtils.h" -//#include "TortoiseDebug.h" -//#include "Translate.h" - -// Strips the last ID from the list -LPITEMIDLIST StripLastID(LPCITEMIDLIST pidl) -{ - TDEBUG_ENTER("StripLastID"); - TDEBUG_TRACE(DisplayNamePIDL(pidl)); - LPMALLOC pMalloc; - if (!SUCCEEDED(SHGetMalloc(&pMalloc))) - return NULL; - - LPCITEMIDLIST pCurrent = pidl; - LPCITEMIDLIST pLast = 0; - DWORD dwSize = 0; - - if (pCurrent->mkid.cb == 0) - { - return 0; - } - - pLast = pCurrent; - pCurrent = (LPCITEMIDLIST) (((LPBYTE) pCurrent) + pCurrent->mkid.cb); - - while (pCurrent->mkid.cb != 0) - { - dwSize += pLast->mkid.cb; - pLast = pCurrent; - pCurrent = (LPITEMIDLIST) (((LPBYTE) pCurrent) + pCurrent->mkid.cb); - } - - LPITEMIDLIST pidlParent = (LPITEMIDLIST) pMalloc->Alloc(dwSize + sizeof(USHORT)); - if (pidlParent != 0) - { - CopyMemory(pidlParent, pidl, dwSize); - *((USHORT*) (((LPBYTE) pidlParent) + dwSize)) = 0; - } - TDEBUG_TRACE(DisplayNamePIDL(pidlParent)); - pMalloc->Release(); - return pidlParent; -} - - - - -// Get the last ID from the list -LPITEMIDLIST GetLastID(LPCITEMIDLIST pidl) -{ - LPMALLOC pMalloc; - if (!SUCCEEDED(SHGetMalloc(&pMalloc))) - return NULL; - - LPCITEMIDLIST pCurrent = pidl; - LPCITEMIDLIST pLast = 0; - - while (pCurrent->mkid.cb != 0) - { - pLast = pCurrent; - pCurrent = (LPITEMIDLIST) (((LPBYTE) pCurrent) + pCurrent->mkid.cb); - } - - LPITEMIDLIST pidlLast = (LPITEMIDLIST) pMalloc->Alloc(pLast->mkid.cb + sizeof(USHORT)); - if (pidlLast != 0) - { - CopyMemory(pidlLast, pLast, pLast->mkid.cb); - *((USHORT*) (((LPBYTE) pidlLast) + pLast->mkid.cb)) = 0; - } - - pMalloc->Release(); - return pidlLast; -} - - -// Bind to parent -IShellFolder* BindToParent(LPCITEMIDLIST pidl) -{ - TDEBUG_ENTER("BindToParent"); - IShellFolder* psfDesktop = 0; - IShellFolder* psfResult = 0; - HRESULT hr = 0; - - LPITEMIDLIST pidlParent = StripLastID(pidl); - TDEBUG_TRACE(DisplayNamePIDL(pidlParent)); - if (!pidlParent) - { - goto Cleanup; - } - - hr = SHGetDesktopFolder(&psfDesktop); - if (FAILED(hr)) - { - goto Cleanup; - } - - if (IsDesktopFolder(pidlParent)) - { - psfResult = psfDesktop; - psfDesktop = 0; - } - else - { - hr = psfDesktop->BindToObject(pidlParent, 0, IID_IShellFolder, - (LPVOID*) &psfResult); - if (FAILED(hr)) - { - goto Cleanup; - } - } - - -Cleanup: - if (psfDesktop) - psfDesktop->Release(); - - if (pidlParent) - ItemListFree(pidlParent); - - return psfResult; -} - - - -std::string DisplayNamePIDL(LPCITEMIDLIST pidl) -{ - SHFILEINFOA sfi; - if (SHGetFileInfoA((LPCSTR) pidl, 0, &sfi, sizeof(sfi), SHGFI_PIDL | SHGFI_DISPLAYNAME) == 0) - { - ASSERT(false); - return "<DisplayNamePIDL failed>"; - } - - return sfi.szDisplayName; -} - - - - -bool LaunchCommand(const std::string& command, bool waitForEnd, bool minimized) -{ - TDEBUG_ENTER("LaunchCommand"); - TDEBUG_TRACE("Command: " << command); - PROCESS_INFORMATION processInfo; - STARTUPINFOA startupInfo; - memset(&startupInfo, 0, sizeof(startupInfo)); - startupInfo.cb = sizeof(startupInfo); - startupInfo.dwFlags = minimized ? STARTF_USESHOWWINDOW : 0; - startupInfo.wShowWindow = SW_SHOWMINIMIZED; - int res = CreateProcessA(0, - const_cast<char*>(command.c_str()), - 0, 0, - FALSE, - //WindowsPlatformIsNT() ? CREATE_NO_WINDOW : 0, - 0, - 0, 0, &startupInfo, &processInfo); - TDEBUG_TRACE("res " << res); - if (res == 0) - { - return false; - } - - if (waitForEnd) - { - TDEBUG_TRACE("Waiting..."); -#if defined(TDEBUG_ON) - DWORD dw = -#endif - WaitWithMsgQueue(1, &processInfo.hProcess, true, INFINITE); - TDEBUG_TRACE("LaunchCommand: dw " << dw); - } - - CloseHandle(processInfo.hProcess); - CloseHandle(processInfo.hThread); - return true; -} - -bool FileIsViewable(const std::string& filename) -{ - // If no application is associated with the file, fail - char buf[MAX_PATH]; - if (int(FindExecutableA(filename.c_str(), "", buf)) == SE_ERR_NOASSOC) - return false; - // Fail if the file is associated with itself (i.e. executable) - if (!strcmpi(filename.c_str(), buf)) - return false; - return true; -} - -bool LaunchFile(const std::string& filename, bool waitForEnd) -{ - TDEBUG_ENTER("LaunchFile"); - - if (!FileIsViewable(filename)) - return false; - - static const char* textExtensions[] = - { - "c", // C source - "cpp", // C++ source - "h", // C/C++ header - "hpp", // C++ header - "txt", // Text file - 0 - }; - bool isTextFile = false; - std::string ext = GetExtension(filename); - for (const char** p = textExtensions; *p; ++p) - if (!strcmp(*p, ext.c_str())) - { - isTextFile = true; - break; - } - - SHELLEXECUTEINFOA sei; - ZeroMemory(&sei, sizeof(sei)); - sei.cbSize = sizeof(sei); - sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI; - sei.lpFile = filename.c_str(); - sei.nShow = SW_SHOW; - sei.lpVerb = isTextFile ? "open" : "edit"; - if (!ShellExecuteExA(&sei)) - { - if (sei.hInstApp == reinterpret_cast<HINSTANCE>(SE_ERR_NOASSOC)) - { - // No association for this extension (typically when file has no extension) - std::ostringstream ss; - ss << "notepad " << filename; - return LaunchCommand(ss.str(), waitForEnd); - } - ASSERT(sei.hInstApp > reinterpret_cast<HINSTANCE>(32)); - return false; - } - - if (waitForEnd && sei.hProcess != 0) - { - TDEBUG_TRACE("Waiting..."); -#if defined(TDEBUG_ON) - DWORD dw = -#endif - WaitWithMsgQueue(1, &sei.hProcess, true, INFINITE); - TDEBUG_TRACE("LaunchCommand: dw " << dw); - } - - if (sei.hProcess != 0) - { - CloseHandle(sei.hProcess); - } - return true; -} - - -// Test if PIDL points to a special folder -bool IsSpecialFolder(LPCITEMIDLIST pidl, int nFolder) -{ - HRESULT hr; - bool result = false; - LPITEMIDLIST mypidl = 0; - hr = SHGetSpecialFolderLocation(NULL, nFolder, &mypidl); - if (FAILED(hr)) - { - goto Cleanup; - } - - result = IsEqualPIDL(pidl, mypidl); - -Cleanup: - if(mypidl) - ItemListFree(mypidl); - - return result; -} - - -// Get IShellFolder from PIDL -IShellFolder* GetIShellFolderFromPIDL(LPCITEMIDLIST pidl) -{ - HRESULT hr; - IShellFolder* psfDesktop = 0; - IShellFolder* psfResult = 0; - hr = SHGetDesktopFolder(&psfDesktop); - if (SUCCEEDED(hr)) - { - hr = psfDesktop->BindToObject(pidl, 0, IID_IShellFolder, (LPVOID*) &psfResult); - if (FAILED(hr)) - { - psfResult = 0; - goto Cleanup; - } - } - -Cleanup: - if (psfDesktop) - psfDesktop->Release(); - return psfResult; -} - - - - -// Rebuild icons -bool RebuildIcons() -{ - TDEBUG_ENTER("RebuildIcons"); - const int BUFFER_SIZE = 1024; - - HKEY hRegKey = 0; - LONG lRegResult = RegOpenKeyExA(HKEY_CURRENT_USER, "Control Panel\\Desktop\\WindowMetrics", - 0, KEY_READ | KEY_WRITE, &hRegKey); - if (lRegResult != ERROR_SUCCESS) - { - TDEBUG_TRACE("Failed to open WindowMetrics key"); - return false; - } - - char* buf = new char[BUFFER_SIZE]; - - // Before Win2k, we're going to change the icon size, otherwise the color depht - std::string sRegValueName; - bool bUseSize = false; - if (WindowsVersionIs2KOrHigher()) - sRegValueName = "Shell Icon BPP"; - else - { - bUseSize = true; - sRegValueName = "Shell Icon Size"; - } - - // Read registry value - DWORD dwSize = BUFFER_SIZE; - lRegResult = RegQueryValueExA(hRegKey, sRegValueName.c_str(), NULL, NULL, (LPBYTE) buf, &dwSize); - if (lRegResult == ERROR_FILE_NOT_FOUND) - { - strncpy(buf, "32", BUFFER_SIZE); - } - else if (lRegResult != ERROR_SUCCESS) - { - TDEBUG_TRACE("Failed to read " << sRegValueName); - RegCloseKey(hRegKey); - return false; - } - - - // Change registry value - DWORD dwRegValue = atoi(buf); - DWORD dwRegValueTemp = 0; - if (!bUseSize) - { - if (dwRegValue == 4) - dwRegValueTemp = 32; - else - dwRegValueTemp = 4; - } - else - { - if (dwRegValue == 31) - dwRegValueTemp = 32; - else - dwRegValueTemp = 31; - } - - dwSize = _snprintf(buf, BUFFER_SIZE, "%d", dwRegValueTemp) + 1; - lRegResult = RegSetValueExA(hRegKey, sRegValueName.c_str(), 0, REG_SZ, (LPBYTE) buf, dwSize); - if (lRegResult != ERROR_SUCCESS) - { - TDEBUG_TRACE("Failed to change " << sRegValueName); - RegCloseKey(hRegKey); - delete[] buf; - return false; - } - - - // Update all windows - PDWORD dwResult; - SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, - 0, SMTO_ABORTIFHUNG, 5000, reinterpret_cast<PDWORD_PTR>(&dwResult)); - - // Reset registry value - dwSize = _snprintf(buf, BUFFER_SIZE, "%d", dwRegValue) + 1; - lRegResult = RegSetValueExA(hRegKey, sRegValueName.c_str(), 0, REG_SZ, (LPBYTE) buf, dwSize); - if(lRegResult != ERROR_SUCCESS) - { - TDEBUG_TRACE("Failed to reset " << sRegValueName); - RegCloseKey(hRegKey); - delete[] buf; - return false; - } - - // Update all windows - SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, - 0, SMTO_ABORTIFHUNG, 5000, reinterpret_cast<PDWORD_PTR>(&dwResult)); - - RegCloseKey(hRegKey); - delete[] buf; - return true; -} - - -// Notify shell of change -void ShellNotifyUpdateFile(const std::string& sFilename) -{ - std::vector<std::string> vFiles; - vFiles.push_back(sFilename); - ShellNotifyUpdateFiles(vFiles); -} - - -// Notify shell of change -void ShellNotifyUpdateFiles(const std::vector<std::string>& sFilenames) -{ - IMalloc *pMalloc = 0; - IShellFolder *pFolder = 0; - LPITEMIDLIST pidl = 0; - std::vector<std::string>::const_iterator it = sFilenames.begin(); - std::wstring wsFilename; - WIN32_FIND_DATAA fd; - HANDLE hFindFile = INVALID_HANDLE_VALUE; - bool bUseWildcards = false; - - // Get malloc - if (!SUCCEEDED(SHGetMalloc(&pMalloc))) - goto Cleanup; - - // Get desktop folder - if (!SUCCEEDED(SHGetDesktopFolder(&pFolder))) - goto Cleanup; - - while (it != sFilenames.end()) - { - // Resolve wildcards - bUseWildcards = (it->find_first_of("*?") != std::string::npos); - if (bUseWildcards) - { - hFindFile = FindFirstFileA(it->c_str(), &fd); - if (hFindFile == INVALID_HANDLE_VALUE) - { - it++; - continue; - } - } - - do - { - // Convert filename to widestring - if (bUseWildcards) - { - std::string s = EnsureTrailingDelimiter(StripLastPart(*it)) + fd.cFileName; - wsFilename = MultibyteToWide(s, 0); - } - else - { - wsFilename = MultibyteToWide(*it, 0); - } - - // Convert filename to ID list - if (!SUCCEEDED(pFolder->ParseDisplayName(0, 0, - (LPWSTR) wsFilename.c_str(), 0, &pidl, 0))) - goto Cleanup; - - // Notify shell - SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_IDLIST | SHCNF_FLUSH, pidl, 0); - - // Release memory - pMalloc->Free(pidl); - pidl = 0; - - } while (bUseWildcards && FindNextFileA(hFindFile, &fd)); - - if (bUseWildcards) - { - FindClose(hFindFile); - hFindFile = INVALID_HANDLE_VALUE; - } - - it++; - } - -Cleanup: - if (hFindFile != INVALID_HANDLE_VALUE) - FindClose(hFindFile); - if (pidl && pMalloc) - pMalloc->Free(pidl); - if (pFolder) - pFolder->Release(); - if (pMalloc) - pMalloc->Release(); -} - - -// Notify shell of change -void ShellNotifyUpdateFiles(const std::string& sDirname, - const std::vector<std::string>& sFilenames) -{ - std::string sFilename; - std::vector<std::string> vFiles; - std::vector<std::string>::const_iterator it = sFilenames.begin(); - while (it != sFilenames.end()) - { - sFilename = EnsureTrailingDelimiter(sDirname) + *it; - vFiles.push_back(sFilename); - it++; - } - ShellNotifyUpdateFiles(vFiles); -} - - - -void ShellNotifyUpdateDir(const std::string& /* sDirname */) -{ -/* std::wstring wsDirname = MultibyteToWide(sDirname); - WCHAR buf[_MAX_PATH]; - wcsncpy(buf, wsDirname.c_str(), _MAX_PATH); - SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH, buf, NULL);*/ -} - - - -// Wait while processing messages -DWORD WaitWithMsgQueue(DWORD nCount, const HANDLE* pHandles, bool fWaitAll, - DWORD dwMilliseconds) -{ - DWORD dw, tcNow, tcEnd, dwTimeToWait; - DWORD dwResult = 0; - MSG msg; - DWORD i; - bool *ba = 0; - HANDLE myHandles[MAXIMUM_WAIT_OBJECTS]; - unsigned int myCount; - - // Initialize handle array - for (i = 0; i < nCount; i++) - { - myHandles[i] = pHandles[i]; - } - myCount = nCount; - - tcNow = GetTickCount(); - tcEnd = tcNow + dwMilliseconds; - - bool bRepeat = true; - while (bRepeat) - { - if ((dwMilliseconds != INFINITE) && (tcNow >= tcEnd)) - { - dwResult = WAIT_TIMEOUT; - goto Cleanup; - } - - if (dwMilliseconds != INFINITE) - { - dwTimeToWait = tcEnd - tcNow; - } - else - { - dwTimeToWait = INFINITE; - } - - dw = MsgWaitForMultipleObjects(myCount, myHandles, false, dwTimeToWait, QS_ALLINPUT); - // Object got signaled - if (dw < (WAIT_OBJECT_0 + myCount)) - { - if (fWaitAll) - { - // Remove object - i = dw - WAIT_OBJECT_0; - myCount--; - for (unsigned int j = i; j < myCount - 1 && myCount > 0; j++) - { - myHandles[j] = myHandles[j + 1]; - } - - // Exit if all objects have been signaled - if (myCount == 0) - { - dwResult = WAIT_OBJECT_0; - goto Cleanup; - } - } - else - { - dwResult = dw; - goto Cleanup; - } - } - // Got message - else if (dw == (WAIT_OBJECT_0 + nCount)) - { - while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) - { - if (msg.message == WM_QUIT) - { - dwResult = dw; - goto Cleanup; - } - - DispatchMessage(&msg); - - // Check for timeout - tcNow = GetTickCount(); - if ((dwMilliseconds != INFINITE) && (tcNow >= tcEnd)) - { - dwResult = WAIT_TIMEOUT; - goto Cleanup; - } - } - } - // WAIT timed out - else if (dw == WAIT_TIMEOUT) - { - dwResult = dw; - goto Cleanup; - } - // WAIT failed - else - { - dwResult = dw; - goto Cleanup; - } - - tcNow = GetTickCount(); - } - -Cleanup: - if (ba) - delete ba; - return dwResult; -} - -// Get path for iconset -std::string GetIconSetPath(const std::string& iconSet) -{ - // No icons => empty path - if (iconSet.empty()) - return ""; - - std::string dir = GetTortoiseDirectory(); - dir = EnsureTrailingDelimiter(dir) + "icons\\" + iconSet; - return EnsureTrailingDelimiter(dir); -} - - -// Get name of iconset -wxString GetIconSetName(const std::string& iconSet) -{ - // No icons => empty path - if (iconSet.empty()) - return wxT(""); - - std::string key("Icons\\"); - key += iconSet; - wxString name(TortoiseRegistry::ReadWxString(key)); - return wxGetTranslation(name); -} - -// Get attributes for file (contains bugfix for SHGetFileInfo) -BOOL MyShellGetFileAttr(const void* data, DWORD *attr, bool bIsPidl) -{ - TDEBUG_ENTER("MyShellGetFileAttr"); -#ifndef UNICODE - // Workaround for NT4 bug: SHGetFileInfoA doesn't work correclty, - // so use SHGetFileInfoW - - if (WindowsVersionIsNT4()) - { - TDEBUG_TRACE("Windows NT4 workaround"); - SHFILEINFOW fi; - std::wstring ws; - DWORD dwFlags = SHGFI_ATTRIBUTES; - if (attr == 0) - { - SetLastError(ERROR_INVALID_PARAMETER); - return false; - } - if (*attr != 0) - { - TDEBUG_TRACE("Attributes: " << *attr); - fi.dwAttributes = *attr; - dwFlags |= SHGFI_ATTR_SPECIFIED; - } - if (bIsPidl) - { - TDEBUG_TRACE("It's a PIDL"); - dwFlags |= SHGFI_PIDL; - } - else - { - TDEBUG_TRACE("It's a path:" << (const char *) data); - ws = MultibyteToWide((const char *) data, 0); - data = ws.c_str(); - } - - DWORD dwResult = SHGetFileInfoW((LPWSTR) data, 0, &fi, sizeof(fi), - dwFlags); - *attr = fi.dwAttributes; - return (dwResult != 0); - } -#endif - - SHFILEINFOA fi; - DWORD dwFlags = SHGFI_ATTRIBUTES; - if (attr != 0) - { - fi.dwAttributes = *attr; - dwFlags |= SHGFI_ATTR_SPECIFIED; - } - if (bIsPidl) - dwFlags |= SHGFI_PIDL; - - DWORD dwResult = SHGetFileInfoA((LPCSTR) data, 0, &fi, sizeof(fi), dwFlags); - *attr = fi.dwAttributes; - return (dwResult != 0); -} - - -// Get attributes for file (contains bugfix for SHGetFileInfo) -BOOL ShellGetFileAttributes(const char* filename, DWORD *attr) -{ - return MyShellGetFileAttr(filename, attr, false); -} - - -// Get attributes for file (contains bugfix for SHGetFileInfo) -BOOL ShellGetFileAttributesPidl(LPCITEMIDLIST pidl, DWORD *attr) -{ - return MyShellGetFileAttr(pidl, attr, true); -} - - -// Get icon size -BOOL ShellGetIconSize(UINT iconsize, int *width, int *height) -{ - SHFILEINFOA sfi; - HIMAGELIST himg = (HIMAGELIST) SHGetFileInfoA("*.txt", FILE_ATTRIBUTE_NORMAL, &sfi, sizeof(sfi), - SHGFI_USEFILEATTRIBUTES | SHGFI_SYSICONINDEX | SHGFI_SHELLICONSIZE | iconsize); - - return ImageList_GetIconSize(himg, width, height); -}
Change 1 of 1 Show Entire File win32/​shellext/​ShellUtils.h Stacked
 
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
@@ -1,128 +0,0 @@
-// TortoiseCVS - a Windows shell extension for easy version control - -// Copyright (C) 2000 - Francis Irving -// <francis@flourish.org> - May 2000 - -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#ifndef SHELL_UTILS_H -#define SHELL_UTILS_H - -#include <windows.h> -#include "FixWinDefs.h" -#include <shlobj.h> -#include <string> -#include <vector> - - -// Explorer pidl data structure walking functions. -// These are probably compatible with Borland builder ones -// of the same name (judging by usenet posting snippets). -// _Who_ invented this stuff in an API? Madness. -LPCITEMIDLIST GetNextItem(LPCITEMIDLIST pidl); -int GetItemCount(LPCITEMIDLIST pidl); -UINT GetSize(LPCITEMIDLIST pidl); -LPITEMIDLIST DuplicateItem(LPMALLOC pMalloc, LPCITEMIDLIST pidl); -// And some more found from usenet, ported from Delphi... -bool IsDesktopFolder(LPCITEMIDLIST pidl); -LPITEMIDLIST AppendPIDL(LPCITEMIDLIST dest, LPCITEMIDLIST src); -// And more... -void ItemListFree(LPITEMIDLIST pidl); -bool IsEqualPIDL(LPCITEMIDLIST a, LPCITEMIDLIST b); // this possibly doesn't work at all, test it when you try to use it -std::string DisplayNamePIDL(LPCITEMIDLIST pidl); - -// From "Shell Clipboard Formats" in the MSDN library: -// << The following two macros can be used to retrieve PIDLs from a CIDA structure. -// The first takes a pointer to the structure and retrieves the PIDL of the parent folder. -// The second takes a pointer to the structure and retrieves one of the other PIDLs, -// identified by its zero-based index. >> -#define GetPIDLFolder(pida) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[0]) -#define GetPIDLItem(pida, i) (LPCITEMIDLIST)(((LPBYTE)pida)+(pida)->aoffset[i+1]) - -// Launch a command, optionally wait for termination -bool LaunchCommand(const std::string& command, bool waitForEnd, bool minimized = false); - -// Return true if it is safe to view this file, i.e. it is not an executable -bool FileIsViewable(const std::string& filename); - -// Launch a file to be opened by the registered type in the shell -bool LaunchFile(const std::string& filename, bool waitForEnd); - -std::string DesktopFolder(); - -// Path of special folder -std::string GetSpecialFolder(int nFolder); - -// Test if PIDL points to a special folder -bool IsSpecialFolder(LPCITEMIDLIST pidl, int nFolder); - -// Get path from IDList -std::string GetPathFromIDList(LPCITEMIDLIST pidl); - -// Strips the last ID from the list -LPITEMIDLIST StripLastID(LPCITEMIDLIST pidl); - -// Get the last ID from the list -LPITEMIDLIST GetLastID(LPCITEMIDLIST pidl); - -// Bind to parent -IShellFolder* BindToParent(LPCITEMIDLIST pidl); - -// Is PIDL a shortcut -bool IsShortcut(LPCITEMIDLIST pidl); - -// Get target of a shortcut -LPITEMIDLIST GetShortcutTarget(LPCITEMIDLIST pidl); - -// Clone a PIDL -LPITEMIDLIST CloneIDList(LPCITEMIDLIST pidl); - - -// Rebuild icons -bool RebuildIcons(); - -// Notify shell of change -void ShellNotifyUpdateFile(const std::string& sFilename); - -// Notify shell of change -void ShellNotifyUpdateFiles(const std::string& sDirname, - const std::vector<std::string>& sFilenames); - -// Notify shell of change -void ShellNotifyUpdateFiles(const std::vector<std::string>& sFilenames); - -void ShellNotifyUpdateDir(const std::string& sDirname); - -// Wait while processing messages -DWORD WaitWithMsgQueue(DWORD nCount, const HANDLE* pHandles, bool fWaitAll, - DWORD dwMilliseconds); - -// Get path for iconset -std::string GetIconSetPath(const std::string& iconSet); - -// Get name of iconset -wxString GetIconSetName(const std::string& iconSet); - -// Get attributes for file (contains bugfix for SHGetFileInfo) -BOOL ShellGetFileAttributes(const char* filename, DWORD *attr); - -// Get attributes for file (contains bugfix for SHGetFileInfo) -BOOL ShellGetFileAttributesPidl(LPCITEMIDLIST pidl, DWORD *attr); - -// Get icon size -BOOL ShellGetIconSize(UINT iconsize, int *width, int *height); - - -#endif
Show Entire File win32/​shellext/​ShellUtils2.cpp Stacked
This file's diff was not loaded because this changeset is very large. Load changes
Show Entire File win32/​shellext/​StringUtils.cpp Stacked
This file's diff was not loaded because this changeset is very large. Load changes
Show Entire File win32/​shellext/​StringUtils.h Stacked
This file's diff was not loaded because this changeset is very large. Load changes
 
47
48
49
50
 
51
52
53
 
47
48
49
 
50
51
52
53
@@ -47,7 +47,7 @@
    fSuccess = ::CallNamedPipeA(   pname.c_str(), (void*)request.c_str(), request.size(), 0, 0, &cbRead, - 200 /* ms */ + NMPWAIT_NOWAIT   );     DWORD err = GetLastError();
Show Entire File win32/​shellext/​TortoiseUtils.cpp Stacked
This file's diff was not loaded because this changeset is very large. Load changes
 
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
5
6
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
9
10
@@ -5,22 +5,6 @@
 #include <windows.h>  #include <string>   -#define _UNUSED_PARAMETER(p) \ - { \ - (p) = (p); \ - } - -extern CRITICAL_SECTION g_critSectionBreak; -template <class T> T GET_SAFE( T a ) {EnterCriticalSection(&g_critSectionBreak); T z = a; LeaveCriticalSection(&g_critSectionBreak); return z;} -template <class T> void SET_SAFE( T & a , T b) {EnterCriticalSection(&g_critSectionBreak); a = b; LeaveCriticalSection(&g_critSectionBreak);} - -#ifndef ARRAYSIZE -#define ARRAYSIZE(a) (sizeof(a)/sizeof(a[0])) -#endif - -extern int LocalToWideChar(LPWSTR pWide, LPTSTR pLocal, DWORD dwChars); -extern int WideCharToLocal(LPTSTR pLocal, LPWSTR pWide, DWORD dwChars); -  #define _MBSTR(wstr) hf_wctomb((LPSTR)alloca(wcslen(wstr) + 1), (wstr),wcslen(wstr) + 1)  #define _WCSTR(str) hf_mbtowc((LPWSTR)alloca((strlen(str) + 1) * sizeof(WCHAR)),(str),strlen(str) + 1)  
 
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
 
14
15
16
 
17
18
19
 
 
 
 
 
 
 
 
 
 
 
20
21
22
@@ -14,21 +14,9 @@
 #include <shlobj.h>  #include <assert.h>  #include <string> -#include <map>    #define ASSERT assert   -typedef std::string wxString; -typedef char wxChar; -#ifdef UNICODE -#define wxT(x) L ## x -#else // !Unicode -#define wxT(x) x -#endif - -#define WindowsVersionIsNT4() (0) - -#define ResultFromShort(i) ResultFromScode(MAKE_SCODE(SEVERITY_SUCCESS, 0, (USHORT)(i)))    #ifdef THG_DEBUG   #include <sstream>