Skip to content

Commit 5ec366d

Browse files
Elminated ILRepack, as it seems to create problems; readjusted all post-build, post-push scripts; removed portable mode from setup (portability is achieved through the ps script;) several minor fixes.
1 parent 1496a44 commit 5ec366d

14 files changed

Lines changed: 356 additions & 119 deletions

.github/workflows/release.yml

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,12 @@ jobs:
3434
- name: List root directory contents
3535
run: ls -R ${{ github.workspace }}
3636

37-
- name: Log timestamps of last changes to relevant files
38-
run: |
39-
echo "Timestamps of last changes to relevant files:"
40-
git log -1 --format="%ci" -- CalibreImport/ReleaseFiles/CalibreImport.config
41-
git log -1 --format="%ci" -- CalibreImport/ReleaseFiles/CalibreImport.dll
42-
git log -1 --format="%ci" -- CalibreImport/ReleaseFiles/Setup.ps1
43-
git log -1 --format="%ci" -- CalibreImport/ReleaseFiles/CalibreImportSetup.exe
44-
4537
- name: Check if relevant files have changed
4638
id: check_files_changed
4739
run: |
4840
git fetch origin master
4941
git checkout master
50-
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- CalibreImport/ReleaseFiles/CalibreImport.config CalibreImport/ReleaseFiles/CalibreImport.dll CalibreImport/ReleaseFiles/Setup.ps1 CalibreImport/ReleaseFiles/CalibreImportSetup.exe)
42+
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD -- CalibreImport/ReleaseFiles/CalibreImport.config CalibreImport/ReleaseFiles/*.dll CalibreImport/ReleaseFiles/Setup.ps1 CalibreImport/ReleaseFiles/CalibreImportSetup.exe)
5143
echo "Changed files: $CHANGED_FILES"
5244
if [ -n "$CHANGED_FILES" ]; then
5345
echo "FILES_CHANGED=true" >> $GITHUB_ENV
@@ -110,7 +102,7 @@ jobs:
110102
if: env.FILES_CHANGED == 'true'
111103
run: |
112104
mkdir -p release
113-
cp $BUILD_PATH/CalibreImport.config $BUILD_PATH/CalibreImport.dll $BUILD_PATH/Setup.ps1 release/
105+
cp $BUILD_PATH/*.dll $BUILD_PATH/CalibreImport.config $BUILD_PATH/Setup.ps1 release/
114106
zip -r ImportToCalibreExtension-v${{ env.NEW_VERSION }}.zip release/
115107
echo "ZIP_FILE=ImportToCalibreExtension-v${{ env.NEW_VERSION }}.zip" >> $GITHUB_ENV
116108
@@ -133,6 +125,10 @@ jobs:
133125
COMMIT_MESSAGE=$(git log -1 --pretty=%B --no-merges)
134126
echo "COMMIT_MESSAGE=$COMMIT_MESSAGE" >> $GITHUB_ENV
135127
128+
- name: Log commit message
129+
run: |
130+
echo "Commit message: ${{ env.COMMIT_MESSAGE }}"
131+
136132
- name: Create Release
137133
if: env.TAG_EXISTS == 'false' && env.FILES_CHANGED == 'true'
138134
id: create_release
@@ -147,14 +143,3 @@ jobs:
147143
prerelease: false
148144
files: ${{ env.ZIP_FILE }},${{ env.SETUP_FILE }}
149145
token: ${{ secrets.PAT_GITHUB }}
150-
151-
# - name: Create pull request
152-
# if: env.FILES_CHANGED == 'true'
153-
# uses: peter-evans/create-pull-request@v4
154-
# with:
155-
# token: ${{ secrets.PAT_GITHUB }}
156-
# commit-message: "Increment version to ${{ env.NEW_VERSION }}"
157-
# branch: version-increment
158-
# title: "Increment version to ${{ env.NEW_VERSION }}"
159-
# body: "This pull request increments the version to ${{ env.NEW_VERSION }} and updates AssemblyInfo.cs."
160-
# base: master

CalibreImport/CalibreContextMenuExtension.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
namespace CalibreImport
2020
{
21-
[ComVisible(true)]
21+
//[ComVisible(true)]
2222
[ClassInterface(ClassInterfaceType.None)]
23+
[Guid("8E5CD5CA-64E0-479A-B62F-B1FC00FF0227"), ComVisible(true)]
2324
[DisplayName("Calibre Import Shell Extension")]
2425
[COMServerAssociation(AssociationType.AllFiles)] //needed for Directory Opus, apparently.
2526
[COMServerAssociation(AssociationType.ClassOfExtension, ".epub", ".pdf", ".mobi", ".azw", ".azw3", ".fb2", ".djvu", ".lrf", ".rtf", ".txt", ".doc", ".docx", ".odt", ".htm", ".html", ".cbz", ".cbr", ".pdb", ".snb", ".tcr", ".zip", ".rar")]
@@ -607,7 +608,6 @@ public static void RegisterExtension(Guid guid, string menuName, List<string> ex
607608
Logger.LogThis("Starting RegisterExtension...", true);
608609
try
609610
{
610-
// Registering the CLSID is not needed as it is done by SharpShell
611611
// Register the context menu handler for each extension
612612
foreach (var ext in extensions)
613613
{
@@ -653,12 +653,12 @@ public static void UnregisterExtension(Guid guid, List<string> extensions)
653653
try
654654
{
655655
Registry.CurrentUser.DeleteSubKeyTree(shellExKeyPath, false);
656-
Logger.LogThis($"Unregistered context menu handler for extension: {ext}", true);
656+
//Logger.LogThis($"Unregistered context menu handler for extension: {ext}", true);
657657
}
658658
catch (ArgumentException)
659659
{
660660
// Key does not exist, ignore
661-
Logger.LogThis($"Registry key does not exist for extension: {ext}", true);
661+
//Logger.LogThis($"Registry key does not exist for extension: {ext}", true);
662662
}
663663
}
664664

@@ -688,4 +688,5 @@ public static void UnregisterExtension(Guid guid, List<string> extensions)
688688
}
689689
}
690690
}
691+
691692
}

CalibreImport/CalibreImport.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<None Include="app.config" />
166166
<None Include="CalibreImportKey.snk" />
167167
<None Include="PostBuild.ps1" />
168+
<None Include="PostBuild2.ps1" />
168169
<None Include="Properties\Settings.settings">
169170
<Generator>SettingsSingleFileGenerator</Generator>
170171
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -173,14 +174,19 @@
173174
<None Include="ReleaseFiles\CalibreImport.config" />
174175
<None Include="ReleaseFiles\Setup.ps1" />
175176
<None Include="ReleaseFiles\CalibreImportSetup.exe" />
176-
<None Include="InnoSetup\CalibreImportSetup.iss" />
177+
<None Include="InnoSetup\CalibreImportSetup.iss" />
177178
<None Include="Setup.ps1">
178179
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
179180
</None>
180181
<None Include="CalibreImport.config">
181182
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
182183
</None>
183184
</ItemGroup>
185+
<ItemGroup>
186+
<Content Include="ReleaseFiles\Newtonsoft.Json.dll" />
187+
<Content Include="ReleaseFiles\SharpShell.dll" />
188+
<Content Include="ReleaseFiles\System.Configuration.ConfigurationManager.dll" />
189+
</ItemGroup>
184190
<!--
185191
Import CSharp targets
186192
-->
@@ -190,7 +196,7 @@
190196
-->
191197
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
192198
<Message Text="Running PostBuild script..." Importance="high" />
193-
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)PostBuild.ps1&quot; -TargetDir &quot;$(TargetDir.TrimEnd('\&quot;'))&quot; -ProjectDir &quot;$(ProjectDir.TrimEnd('\&quot;'))&quot;" />
199+
<Exec Command="powershell -ExecutionPolicy Bypass -File &quot;$(ProjectDir)PostBuild2.ps1&quot; -TargetDir &quot;$(TargetDir.TrimEnd('\&quot;'))&quot; -ProjectDir &quot;$(ProjectDir.TrimEnd('\&quot;'))&quot;" />
194200
<Message Text="PostBuild script completed." Importance="high" />
195201
</Target>
196202
</Project>
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#define ReleaseFilesPath "..\ReleaseFiles\"
2+
#define AppName "CalibreImport"
3+
4+
[Setup]
5+
AppName={#AppName}
6+
AppVersion=1.0
7+
DefaultDirName={pf}\{#AppName}
8+
DefaultGroupName={#AppName}
9+
UninstallDisplayIcon={app}\{#AppName}.dll
10+
OutputDir={#ReleaseFilesPath}
11+
OutputBaseFilename=CalibreImportSetup
12+
Compression=lzma
13+
SolidCompression=yes
14+
PrivilegesRequired=admin
15+
16+
[Files]
17+
; Install all DLLs to application directory
18+
Source: "{#ReleaseFilesPath}*.dll"; DestDir: "{app}"; Flags: ignoreversion
19+
; Install config file to AppData
20+
Source: "{#ReleaseFilesPath}*.config"; DestDir: "{userappdata}\{#AppName}"; Flags: ignoreversion
21+
22+
[Code]
23+
function IsDotNet48Installed: Boolean;
24+
var
25+
ReleaseVersion: Cardinal;
26+
begin
27+
Result := False;
28+
if RegKeyExists(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full') then
29+
begin
30+
if RegQueryDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full', 'Release', ReleaseVersion) then
31+
begin
32+
Result := (ReleaseVersion >= 528040);
33+
end;
34+
end;
35+
end;
36+
37+
procedure RegisterDLLs;
38+
var
39+
FindRec: TFindRec;
40+
RegAsmPath: String;
41+
ResultCode: Integer;
42+
begin
43+
RegAsmPath := ExpandConstant('{win}\Microsoft.NET\Framework\v4.0.30319\regasm.exe');
44+
if not FileExists(RegAsmPath) then
45+
RegAsmPath := ExpandConstant('{win}\Microsoft.NET\Framework64\v4.0.30319\regasm.exe');
46+
47+
if FindFirst(ExpandConstant('{app}\*.dll'), FindRec) then
48+
begin
49+
try
50+
repeat
51+
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then
52+
begin
53+
if not Exec(RegAsmPath, ExpandConstant('"{app}\' + FindRec.Name + '" /codebase'), '',
54+
SW_HIDE, ewWaitUntilTerminated, ResultCode) then
55+
MsgBox('Failed to register ' + FindRec.Name + ': ' + SysErrorMessage(ResultCode), mbError, MB_OK)
56+
else if ResultCode <> 0 then
57+
MsgBox('Registration failed for ' + FindRec.Name + ' with code: ' + IntToStr(ResultCode), mbError, MB_OK);
58+
end;
59+
until not FindNext(FindRec);
60+
finally
61+
FindClose(FindRec);
62+
end;
63+
end;
64+
end;
65+
66+
procedure InitializeWizard;
67+
begin
68+
if not IsDotNet48Installed then
69+
begin
70+
MsgBox('This application requires .NET Framework 4.8. Please install it and then run this setup again.', mbError, MB_OK);
71+
Abort;
72+
end;
73+
end;
74+
75+
procedure CurStepChanged(CurStep: TSetupStep);
76+
begin
77+
if CurStep = ssPostInstall then
78+
begin
79+
RegisterDLLs;
80+
end;
81+
end;

CalibreImport/InnoSetup/CalibreImportSetup.iss

Lines changed: 68 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
#define AppDll "CalibreImport.dll"
22
#define ConfigFile "CalibreImport.config"
33
#define ReleaseFilesPath "..\ReleaseFiles\"
4+
#define AppName "CalibreImport"
45

56
[Setup]
6-
AppName=YourAppName
7+
AppName={#AppName}
78
AppVersion=1.0
8-
DefaultDirName={pf}\CalibreImport
9-
DefaultGroupName=Calibre Import Shell Extension
10-
UninstallDisplayIcon={app}\YourApp.exe
9+
DefaultDirName={pf}\{#AppName}
10+
DefaultGroupName={#AppName}
11+
UninstallDisplayIcon={app}\{#AppDll}
1112
OutputDir={#ReleaseFilesPath}
1213
OutputBaseFilename=CalibreImportSetup
1314
Compression=lzma
1415
SolidCompression=yes
16+
PrivilegesRequired=admin
1517

1618
[Files]
17-
Source: "{#ReleaseFilesPath}{#AppDll}"; DestDir: "{app}"; Flags: ignoreversion
18-
Source: "{#ReleaseFilesPath}{#ConfigFile}"; DestDir: "{userappdata}\YourAppName"; Flags: ignoreversion
19-
20-
[Icons]
21-
Name: "{group}\YourAppName"; Filename: "{app}\YourApp.exe"
19+
; These will only be used in non-portable mode
20+
Source: "{#ReleaseFilesPath}{#AppDll}"; DestDir: "{app}"; Flags: ignoreversion; Check: ShouldInstallToProgramFiles
21+
Source: "{#ReleaseFilesPath}{#ConfigFile}"; DestDir: "{userappdata}\{#AppName}"; Flags: ignoreversion; Check: ShouldInstallToAppData
2222

2323
[Code]
2424
const
25-
AppDll = '{#AppDll}'; // Use preprocessor variable
26-
ConfigFile = '{#ConfigFile}'; // Use preprocessor variable
27-
ReleaseFilesPath = '{#ReleaseFilesPath}'; // Use preprocessor variable
25+
AppDll = '{#AppDll}';
26+
ConfigFile = '{#ConfigFile}';
27+
ReleaseFilesPath = '{#ReleaseFilesPath}';
28+
AppName = '{#AppName}';
2829
2930
var
3031
PortableMode: Boolean;
@@ -47,6 +48,21 @@ begin
4748
end;
4849
end;
4950
51+
function ShouldInstallToProgramFiles: Boolean;
52+
begin
53+
Result := not PortableMode;
54+
end;
55+
56+
function ShouldInstallToAppData: Boolean;
57+
begin
58+
Result := not PortableMode;
59+
end;
60+
61+
procedure UpdatePortableMode(Sender: TObject);
62+
begin
63+
PortableMode := PortableModeCheck.Checked;
64+
end;
65+
5066
procedure InitializeWizard;
5167
begin
5268
{ Check for .NET Framework 4.8 }
@@ -59,18 +75,17 @@ begin
5975
{ Initialize variables }
6076
PortableMode := False;
6177
RestartExplorer := False;
62-
63-
{ Initialize InstallPath with a default directory }
64-
InstallPath := ExpandConstant('{sd}'); // Default to the system drive (e.g., C:\)
78+
InstallPath := ExpandConstant('{sd}');
6579
6680
{ Create a checkbox for portable mode }
6781
PortableModeCheck := TNewCheckBox.Create(WizardForm);
6882
PortableModeCheck.Parent := WizardForm.SelectDirPage;
69-
PortableModeCheck.Left := WizardForm.DirEdit.Left; // Use DirEdit instead of SelectDirLabel
83+
PortableModeCheck.Left := WizardForm.DirEdit.Left;
7084
PortableModeCheck.Top := WizardForm.DirEdit.Top + WizardForm.DirEdit.Height + 10;
71-
PortableModeCheck.Width := WizardForm.DirEdit.Width; // Use DirEdit instead of SelectDirLabel
85+
PortableModeCheck.Width := WizardForm.DirEdit.Width;
7286
PortableModeCheck.Caption := 'Install in portable mode';
7387
PortableModeCheck.Checked := PortableMode;
88+
PortableModeCheck.OnClick := @UpdatePortableMode;
7489
7590
{ Create a checkbox for restarting Explorer }
7691
RestartExplorerCheck := TNewCheckBox.Create(WizardForm);
@@ -85,34 +100,60 @@ end;
85100
procedure CurStepChanged(CurStep: TSetupStep);
86101
var
87102
SourceAppDll, SourceConfigFile: String;
88-
ResultCode: Integer; // Declare ResultCode variable
103+
ResultCode: Integer;
104+
RegAsmPath: String;
89105
begin
90106
if CurStep = ssPostInstall then
91107
begin
108+
{ Update checkbox states }
109+
PortableMode := PortableModeCheck.Checked;
110+
RestartExplorer := RestartExplorerCheck.Checked;
111+
92112
{ Resolve the full paths to the source files }
93113
SourceAppDll := ExpandConstant('{src}\' + ReleaseFilesPath + AppDll);
94114
SourceConfigFile := ExpandConstant('{src}\' + ReleaseFilesPath + ConfigFile);
95115
96116
if PortableMode then
97117
begin
118+
{ Create directory if it doesn't exist }
119+
if not DirExists(InstallPath) then
120+
ForceDirectories(InstallPath);
121+
98122
{ Copy files to the selected folder }
99-
FileCopy(SourceAppDll, InstallPath + '\' + AppDll, False);
100-
FileCopy(SourceConfigFile, InstallPath + '\' + ConfigFile, False);
123+
if not FileCopy(SourceAppDll, InstallPath + '\' + AppDll, False) then
124+
MsgBox('Failed to copy DLL to portable location', mbError, MB_OK);
125+
if not FileCopy(SourceConfigFile, InstallPath + '\' + ConfigFile, False) then
126+
MsgBox('Failed to copy config to portable location', mbError, MB_OK);
127+
128+
{ Register DLL from portable location }
129+
RegAsmPath := ExpandConstant('{win}\Microsoft.NET\Framework\v4.0.30319\regasm.exe');
130+
if not FileExists(RegAsmPath) then
131+
RegAsmPath := ExpandConstant('{win}\Microsoft.NET\Framework64\v4.0.30319\regasm.exe');
132+
133+
if not Exec(RegAsmPath, '"' + InstallPath + '\' + AppDll + '" /codebase', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
134+
MsgBox('Failed to register DLL: ' + SysErrorMessage(ResultCode), mbError, MB_OK)
135+
else if ResultCode <> 0 then
136+
MsgBox('DLL registration failed with code: ' + IntToStr(ResultCode), mbError, MB_OK);
101137
end
102138
else
103139
begin
104-
{ Copy files to Program Files and AppData }
105-
FileCopy(SourceAppDll, ExpandConstant('{pf}\YourAppName\' + AppDll), False);
106-
FileCopy(SourceConfigFile, ExpandConstant('{userappdata}\YourAppName\' + ConfigFile), False);
140+
{ For non-portable mode, files are already installed by the [Files] section }
141+
{ Register DLL from installation directory }
142+
RegAsmPath := ExpandConstant('{win}\Microsoft.NET\Framework\v4.0.30319\regasm.exe');
143+
if not FileExists(RegAsmPath) then
144+
RegAsmPath := ExpandConstant('{win}\Microsoft.NET\Framework64\v4.0.30319\regasm.exe');
145+
146+
if not Exec(RegAsmPath, ExpandConstant('"{app}\' + AppDll + '" /codebase'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
147+
MsgBox('Failed to register DLL: ' + SysErrorMessage(ResultCode), mbError, MB_OK)
148+
else if ResultCode <> 0 then
149+
MsgBox('DLL registration failed with code: ' + IntToStr(ResultCode), mbError, MB_OK);
107150
end;
108151
109-
{ Register the DLL using regasm }
110-
Exec(ExpandConstant('{win}\Microsoft.NET\Framework\v4.0.30319\regasm.exe'), ExpandConstant('"{app}\' + AppDll + '" /codebase'), '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
111-
112152
if RestartExplorer then
113153
begin
114154
{ Restart Windows Explorer }
115-
Exec('taskkill.exe', '/f /im explorer.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
155+
if not Exec('taskkill.exe', '/f /im explorer.exe', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) then
156+
MsgBox('Failed to kill explorer: ' + SysErrorMessage(ResultCode), mbError, MB_OK);
116157
Exec('explorer.exe', '', '', SW_HIDE, ewNoWait, ResultCode);
117158
end;
118159
end;

0 commit comments

Comments
 (0)