15
15
16
16
17
17
//Update this when releasing a new version
18
- #define public Version ' 1.1.0 '
18
+ #define public Version ' 1.1.2 '
19
19
20
20
//This defines in which sub folder of this project the current files are located
21
21
#define public HackMonospaced_Sourcefolder ' Hack_v2_020'
47
47
#define public FontCacheService ' FontCache'
48
48
#define public FontCache30Service ' FontCache3.0.0.0'
49
49
50
+ //File name of the FontState Log
51
+ #define public LogFontDataFilename ' Log-FontData.txt'
52
+ #define public LogFontDataFilenameOld ' Log-FontData-old.txt'
53
+
54
+
50
55
51
56
//Total number of font entries we have
52
57
#define total_fonts 4
@@ -240,8 +245,10 @@ Filename: "{app}\InstallInfo.ini"; Section: "Main"; Key: "Version"; String: "{#V
240
245
Filename : " {app} \InstallInfo.ini" ; Section: " Main" ; Key: " Name" ; String : " {#AppName}"
241
246
242
247
[UninstallDelete]
243
- ;Delete Install Info
248
+ ;Delete install Info
244
249
Type : files ; Name : " {app} \InstallInfo.ini"
250
+ ;Delete log files
251
+ Type : files ; Name : " {app} \Log*.txt"
245
252
246
253
247
254
@@ -292,7 +299,7 @@ const
292
299
293
300
var
294
301
// Custom "prepare to install" page
295
- customPrepareToInstall : TOutputProgressWizardPage;
302
+ customProgressPage : TOutputProgressWizardPage;
296
303
297
304
// All font files included in this setup
298
305
FontFiles: array of string;
314
321
// If this true we will make changes to this system
315
322
ChangesRequired:boolean;
316
323
324
+ // In memory buffer for the "Font" messages written to the special log file ({#LogFontDataFilename})
325
+ FontStateBuffer: array of string;
326
+
317
327
318
328
// #######################################################################################
319
329
// Service control code from http://www.vincenzo.net/isxkb/index.php?title=Service_-_Functions_to_Start%2C_Stop%2C_Install%2C_Remove_a_Service
@@ -463,6 +473,20 @@ begin
463
473
464
474
end ;
465
475
476
+ // Logs to the internal buffer which will then be written to the installation folder at the end of the setup
477
+ procedure LogAsImportant (message:string);
478
+ var
479
+ curSize: integer;
480
+ begin
481
+ // Always write the message to the "normal" log as well
482
+
483
+ log(message);
484
+
485
+ curSize:=GetArrayLength(FontStateBuffer);
486
+ SetArrayLength(FontStateBuffer, curSize+1 );
487
+ FontStateBuffer[curSize]:=message;
488
+ end ;
489
+
466
490
467
491
procedure InitializeWizard ;
468
492
var
@@ -483,7 +507,7 @@ begin
483
507
484
508
// subTitle contains [name] which we need to replace
485
509
StringChangeEx(subTitle, ' [name]' , ' {#AppName}' , True);
486
- customPrepareToInstall :=CreateOutputProgressPage(title, subTitle);
510
+ customProgressPage :=CreateOutputProgressPage(title, subTitle);
487
511
end ;
488
512
489
513
510
534
i:integer;
511
535
entryFound:boolean;
512
536
registryFontValue:string;
537
+ expectedFontValue:string;
513
538
begin
514
- log (' IsSetupFontSameAsInstalledFont(): ' + fileName);
539
+ LogAsImportant (' IsSetupFontSameAsInstalledFont(): ' + fileName);
515
540
516
541
result:=false;
517
542
entryFound:=false;
@@ -522,21 +547,27 @@ begin
522
547
if FontFiles[i]=fileName then begin
523
548
entryFound:=true;
524
549
550
+ // If the hash of the file does not match the font installed, the registry check is not required since we need to install it anyway
525
551
if FontFilesHashes[i]=InstalledFontsHashes[i] then begin
552
+ expectedFontValue:=FontFilesNames[i]+' (TrueType)' ;
553
+ LogAsImportant(' Hash matches, checking for registry value: ' + expectedFontValue);
554
+
526
555
// Now check if the font registration info in the registry also matches
527
- if RegQueryStringValue(HKLM, ' SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' , FontFilesNames[i]+ ' (TrueType) ' , registryFontValue) then begin
556
+ if RegQueryStringValue(HKLM, ' SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts' , expectedFontValue , registryFontValue) then begin
528
557
// Does the value point to the same file as we have in setup?
529
558
if registryFontValue=fileName then begin
559
+ LogAsImportant(' Registry data matches, installation not required' );
530
560
result:=true; // all is exactly as expected
531
- end else begin
532
- log(' File name in registry is different, installation required' );
561
+ end else begin
562
+ LogAsImportant(' Value found : ' + registryFontValue);
563
+ LogAsImportant(' File name in registry is different, installation required' );
533
564
end ;
534
565
end else begin
535
- log (' Font not found in registry, installation required' );
566
+ LogAsImportant (' Font not found in registry, installation required' );
536
567
end ;
537
568
end else begin
538
- log (' Hash values (Setup/Windows): ' + FontFilesHashes[i] + ' / ' + InstalledFontsHashes[i]);
539
- log (' File is different, installation required' );
569
+ LogAsImportant (' Hash values (Setup/Windows): ' + FontFilesHashes[i] + ' / ' + InstalledFontsHashes[i]);
570
+ LogAsImportant (' File is different, installation required' );
540
571
end ;
541
572
542
573
end ;
@@ -559,14 +590,15 @@ var
559
590
begin
560
591
result:=false;
561
592
562
- log (' Checking for differences between fonts in setup and this system' );
593
+ LogAsImportant (' Checking for differences between fonts in setup and this system' );
563
594
564
595
for i := 0 to GetArrayLength(FontFiles)-1 do begin
565
596
if IsSetupFontSameAsInstalledFont(FontFiles[i]) then begin
566
597
// File is the same, ignore
567
598
end else begin
568
599
// We have a change, installation is required!
569
- log(' Found difference for file ' + FontFiles[i]);
600
+ LogAsImportant(' Found difference for file ' + FontFiles[i]);
601
+ LogAsImportant(' Installation required.' );
570
602
571
603
// One detected difference is enough to result TRUE
572
604
result:=true;
@@ -635,24 +667,33 @@ var
635
667
currentFontFileNameWindows:string;
636
668
637
669
begin
638
- log(' ---BeforeInstallAction START---' );
670
+ LogAsImportant(' ---BeforeInstallAction START---' );
671
+
672
+ // Write system information to log file
673
+ LogAsImportant(' Setup version: {#Version}' );
674
+ LogAsImportant(' Font version.: {#HackMonospaced_Version}' );
675
+ LogAsImportant(' Local time...: ' + GetDateTimeString(' yyyy-dd-mm hh:nn' , ' -' , ' :' ));
676
+ LogAsImportant(' Fonts folder.: ' + ExpandConstant(' {fonts}' ));
677
+ LogAsImportant(' Dest folder..: ' + ExpandConstant(' {app}' ));
678
+
639
679
640
- customPrepareToInstall.SetProgress(0 , 0 );
641
- customPrepareToInstall.Show;
680
+
681
+ customProgressPage.SetProgress(0 , 0 );
682
+ customProgressPage.Show;
642
683
643
684
try
644
685
begin
645
-
686
+
646
687
// Calculate the SHA1 hash for *ALL* fonts we support
647
- customPrepareToInstall .SetText(' Calculating hashes for fonts already installed...' , ' ' );
688
+ customProgressPage .SetText(' Calculating hashes for fonts already installed...' , ' ' );
648
689
649
690
SetArrayLength(InstalledFontsHashes, GetArrayLength(FontFiles));
650
691
651
- log (' ---HASH CALCULATION---' );
692
+ LogAsImportant (' ---HASH CALCULATION---' );
652
693
for i := 0 to GetArrayLength(FontFiles)-1 do begin
653
694
currentFont:=FontFiles[i];
654
- log (' Calculating hash for ' +currentFont);
655
- log (' File from setup: ' + FontFilesHashes[i]);
695
+ LogAsImportant (' Calculating hash for ' +currentFont);
696
+ LogAsImportant (' File from setup: ' + FontFilesHashes[i]);
656
697
657
698
currentFontFileNameWindows:=ExpandConstant(' {fonts}\' +currentFont);
658
699
@@ -663,9 +704,9 @@ begin
663
704
InstalledFontsHashes[i]:=' -NOT FOUND-' ;
664
705
end ;
665
706
666
- log (' File in \fonts : ' + InstalledFontsHashes[i]);
707
+ LogAsImportant (' File in \fonts : ' + InstalledFontsHashes[i]);
667
708
end ;
668
- log (' ----------------------' );
709
+ LogAsImportant (' ----------------------' );
669
710
670
711
671
712
// Set it to false by default
@@ -685,10 +726,10 @@ begin
685
726
FontCache30Service_Stopped:=false;
686
727
687
728
if ChangesRequired=true then begin
688
- customPrepareToInstall .SetText(' Stopping service {#FontCacheService}...' ,' ' );
729
+ customProgressPage .SetText(' Stopping service {#FontCacheService}...' ,' ' );
689
730
FontCacheService_Stopped:=StopNTService2(' {#FontCacheService}' );
690
731
691
- customPrepareToInstall .SetText(' Stopping service {#FontCache30Service}...' ,' ' );
732
+ customProgressPage .SetText(' Stopping service {#FontCache30Service}...' ,' ' );
692
733
FontCache30Service_Stopped:=StopNTService2(' {#FontCache30Service}' )
693
734
end ;
694
735
@@ -697,50 +738,76 @@ begin
697
738
698
739
end ;
699
740
finally
700
- customPrepareToInstall .Hide;
741
+ customProgressPage .Hide;
701
742
end ;
702
743
703
744
BeforeInstallActionWasRun:=true;
704
- log (' ---BeforeInstallAction END---' );
745
+ LogAsImportant (' ---BeforeInstallAction END---' );
705
746
end ;
706
747
707
748
708
749
709
750
// Show a custom prepare to install page in order to give the user output what we are doing
710
751
procedure AfterInstallAction ();
752
+ var
753
+ appDestinationFolder:string;
754
+
711
755
begin
712
756
log(' ---AfterInstallAction START---' );
713
757
714
- customPrepareToInstall .SetProgress(0 , 0 );
715
- customPrepareToInstall .Show;
758
+ customProgressPage .SetProgress(0 , 0 );
759
+ customProgressPage .Show;
716
760
717
761
try
718
762
begin
719
763
720
764
// Start the service the before action has stopped
721
- customPrepareToInstall .SetText(' Starting service {#FontCacheService}...' ,' ' );
765
+ customProgressPage .SetText(' Starting service {#FontCacheService}...' ,' ' );
722
766
if FontCacheService_Stopped=true then begin
723
767
StartNTService2(' {#FontCacheService}' );
724
768
FontCacheService_Stopped:=false;
725
769
end ;
726
770
727
- customPrepareToInstall .SetText(' Starting service {#FontCache30Service}...' ,' ' );
771
+ customProgressPage .SetText(' Starting service {#FontCache30Service}...' ,' ' );
728
772
if FontCache30Service_Stopped=true then begin
729
773
StartNTService2(' {#FontCache30Service}' );
730
774
FontCache30Service_Stopped:=false;
731
775
end ;
732
776
733
-
734
- // Finally, inform windows that fonts have changed (just to be sure we do this always)
777
+ // Inform windows that fonts have changed (just to be sure we do this always)
735
778
// See https://msdn.microsoft.com/en-us/library/windows/desktop/dd183326%28v=vs.85%29.aspx
736
779
SendBroadcastMessage(29 , 0 , 0 );
737
780
// HWND_BROADCAST = -1
738
781
// WM_FONTCHANGE = 0x1D = 29
739
782
740
-
783
+ customProgressPage.SetText(' Storing font data...' ,' ' );
784
+
785
+ // Write the buffer to disk. We better make sure that {app} exists.
786
+ appDestinationFolder:=ExpandConstant(' {app}' );
787
+ appDestinationFolder:=AddBackslash(appDestinationFolder);
788
+ if DirExists(appDestinationFolder) then begin
789
+
790
+ // Check if there is already a current log. If so, rename it.
791
+ If FileExists(appDestinationFolder + ' {#LogFontDataFilename}' ) then begin
792
+
793
+ // Check if and "old" file already exists. If so, delete it.
794
+ If FileExists(appDestinationFolder + ' {#LogFontDataFilenameOld}' ) then begin
795
+ DeleteFile(appDestinationFolder + ' {#LogFontDataFilenameOld}' );
796
+ end ;
797
+
798
+ // Rename current file to old
799
+ RenameFile(appDestinationFolder + ' {#LogFontDataFilename}' , appDestinationFolder + ' {#LogFontDataFilenameOld}' );
800
+ end ;
801
+
802
+ // Save the buffer
803
+ log(' Saving font state to ' + appDestinationFolder + ' {#LogFontDataFilename}' );
804
+ SaveStringsToFile(appDestinationFolder + ' {#LogFontDataFilename}' , FontStateBuffer, false); // do not append
805
+ end ;
806
+
807
+
741
808
end ;
742
809
finally
743
- customPrepareToInstall .Hide;
810
+ customProgressPage .Hide;
744
811
end ;
745
812
746
813
log(' ---AfterInstallAction END---' );
@@ -755,7 +822,7 @@ begin
755
822
756
823
log(' ---NeedRestart---' );
757
824
if ChangesRequired then
758
- log (' Changes detected, require reboot' );
825
+ LogAsImportant (' Changes detected, require reboot' );
759
826
760
827
result:=ChangesRequired;
761
828
0 commit comments