Skip to content

Commit a69fa3d

Browse files
committed
* Improve installer:
* close DirectoryOpus before installation * simplify installer source code * Update C++ 3rd party dependencies * ExifTool * Update binaries to a newer version * Check that tag names are passed correctly inside the GetInfoAsJson method
1 parent a829862 commit a69fa3d

16 files changed

Lines changed: 82 additions & 133 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,11 @@ for (var tagName in tags) {
268268
```
269269

270270
#### Getting only specific tags
271-
`GetInfoAsJson` method accepts the array of tag names. The output will only contain these specific tags. The tag names are passed to the ExifTool executable as `-TAG` command line arguments.
271+
`GetInfoAsJson` method accepts the array of tag names in format `Group0:TagName`. The output will only contain these specific tags. The tag names are passed to the ExifTool executable as `-TAG` command line arguments.
272272
```javascript
273273
var jsonString = exifTool.GetInfoAsJson(
274274
"C:/Windows/SystemResources/Windows.UI.SettingsAppThreshold/SystemSettings/Assets/HDRSample.mkv",
275-
["TrackType", "DocTypeVersion"])
275+
["Matroska:TrackType", "Matroska:DocTypeVersion"])
276276
```
277277

278278
# How to use

build.ps1

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,16 @@ Function FindVcPkg() {
4141
return "$installationPath/VC/vcpkg/vcpkg.exe"
4242
}
4343

44-
Function CreateZipArchive($fileFullName, $archiveFullName) {
45-
Info "Create zip archive `n $archiveFullName from `n $fileFullName"
46-
Compress-Archive -Force -Path $fileFullName -DestinationPath $archiveFullName
47-
}
48-
49-
Function GetVersion() {
44+
Function GetInstallerVersion() {
5045
$gitCommand = Get-Command -Name git
5146

5247
try { $tag = & $gitCommand describe --exact-match --tags HEAD 2> $null } catch { }
5348
if(-Not $?) {
54-
Info "The commit is not tagged. Use 'v0.0-dev' as a tag instead"
55-
$tag = "v0.0-dev"
49+
Info "The commit is not tagged. Use 'v0.0' as a tag instead"
50+
$tag = "v0.0"
5651
}
5752

58-
$commitHash = & $gitCommand rev-parse --short HEAD
59-
CheckReturnCodeOfPreviousCommand "Failed to get git commit hash"
60-
61-
return "$($tag.Substring(1))-$commitHash"
62-
}
63-
64-
Function GetInstallerVersion($version) {
65-
return $version.Split("-")[0];
53+
return $tag.Substring(1)
6654
}
6755

6856
Set-StrictMode -Version Latest
@@ -71,12 +59,11 @@ $ProgressPreference = "SilentlyContinue"
7159

7260
$root = Resolve-Path $PSScriptRoot
7361
$buildDir = "$root/build"
74-
$version = GetVersion
75-
$installerVersion = GetInstallerVersion $version
62+
$installerVersion = GetInstallerVersion
7663
$msbuild = FindMsBuild
7764
$vcPkg = FindVcPkg
7865

79-
Info "Version: '$version'. InstallerVersion: '$installerVersion'"
66+
Info "InstallerVersion: '$installerVersion'"
8067

8168
Info "Integrate VcPkg"
8269
& $vcPkg integrate install
@@ -88,7 +75,6 @@ Info "Build project"
8875
/verbosity:minimal `
8976
/property:Configuration=Release `
9077
/property:DebugType=None `
91-
/property:Version=$version `
9278
/property:InstallerVersion=$installerVersion `
9379
$root/DOpusScriptingExtensions.sln
9480
CheckReturnCodeOfPreviousCommand "build failed"
@@ -97,7 +83,7 @@ Info "Run tests"
9783
cscript $root/src/test/test.js
9884
CheckReturnCodeOfPreviousCommand "tests failed"
9985

100-
Info "Copy installer to the Publish directory"
86+
Info "Copy installer to the Publish directory and create zip archive"
10187
New-Item -Force -ItemType "directory" $buildDir/Publish > $null
10288
Copy-Item -Force -Path $buildDir/x64/Release/Installer/Installer.msi -Destination $buildDir/Publish/DOpusScriptingExtensions.msi > $null
103-
CreateZipArchive $buildDir/Publish/DOpusScriptingExtensions.msi $buildDir/Publish/DOpusScriptingExtensions.msi.zip
89+
Compress-Archive -Force -Path $buildDir/Publish/DOpusScriptingExtensions.msi -DestinationPath $buildDir/Publish/DOpusScriptingExtensions.msi.zip

src/DOpusScriptingExtensions/DOpusScriptingExtensions.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "Utils/Exceptions.h"
66
#include "Utils/ComUtils.h"
77
#include "Utils/WinApiUtils.h"
8-
#include "Utils/NonCopyableAndNonMovable.h"
98
#include "ProcessRunner/ProcessRunnerResult.h"
109
#include "ProcessRunner/ProcessRunner.h"
1110
#include "FileMimeTypeDetector/LibMagicWrapper.h"

src/DOpusScriptingExtensions/DOpusScriptingExtensions.rc

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ BEGIN
7575
BEGIN
7676
BLOCK "040904B0"
7777
BEGIN
78-
VALUE "CompanyName", "TODO: <Company name>"
79-
VALUE "FileDescription", "TODO: <File description>"
78+
VALUE "CompanyName", "PolarGoose"
8079
VALUE "FileVersion", "1.0.0.1"
81-
VALUE "LegalCopyright", "TODO: (c) <Company name>. All rights reserved."
8280
VALUE "InternalName", "DOpusScriptingExtensions.dll"
8381
VALUE "OriginalFilename", "DOpusScriptingExtensions.dll"
84-
VALUE "ProductName", "TODO: <Product name>"
82+
VALUE "ProductName", "DOpusScriptingExtensions"
8583
VALUE "ProductVersion", "1.0.0.1"
8684
END
8785
END

src/DOpusScriptingExtensions/DOpusScriptingExtensions.vcxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@
154154
<ClInclude Include="targetver.h" />
155155
<ClInclude Include="utils\ComUtils.h" />
156156
<ClInclude Include="Utils\Exceptions.h" />
157-
<ClInclude Include="Utils\NonCopyableAndNonMovable.h" />
158157
<ClInclude Include="Utils\StringUtils.h" />
159158
<ClInclude Include="Utils\WinApiUtils.h" />
160159
</ItemGroup>
@@ -195,10 +194,11 @@
195194
<Copy SourceFiles="$(ProjectRoot)/vcpkg_installed/x64-windows-static/vcpkg/pkgs/libmagic_x64-windows/share/libmagic/misc/magic.mgc" DestinationFolder="$(OutputPath)" />
196195
</Target>
197196
<Target Name="DownloadExifTool" AfterTargets="Build" Condition="!Exists('$(BuildFolder)exiftool.zip')">
198-
<DownloadFile SourceUrl="https://exiftool.org/exiftool-13.27_64.zip" DestinationFolder="$(BuildFolder)" DestinationFileName="exiftool.zip" />
197+
<DownloadFile SourceUrl="https://exiftool.org/exiftool-13.30_64.zip" DestinationFolder="$(BuildFolder)" DestinationFileName="exiftool.zip" />
199198
<Unzip SourceFiles="$(BuildFolder)exiftool.zip" DestinationFolder="$(BuildFolder)" />
200199
</Target>
201200
<Target Name="CopyExifToolToOutputFolder" AfterTargets="DownloadExifTool" Condition="!Exists('$(OutputPath)exiftool')">
202-
<Exec Command="robocopy &quot;$(BuildFolder)exiftool-13.27_64&quot; &quot;$(OutputPath)exiftool&quot; /e &gt; nul" ContinueOnError="True" />
201+
<Exec Command="robocopy &quot;$(BuildFolder)exiftool-13.30_64&quot; &quot;$(OutputPath)exiftool&quot; /e &gt; nul" ContinueOnError="True" />
202+
<Exec Command="ren &quot;$(OutputPath)exiftool\exiftool(-k).exe&quot; &quot;exiftool.exe&quot;" />
203203
</Target>
204-
</Project>
204+
</Project>

src/DOpusScriptingExtensions/DOpusScriptingExtensions.vcxproj.filters

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
<ClInclude Include="FileMimeTypeDetector\LibMagicWrapper.h">
5656
<Filter>FileMimeTypeDetector</Filter>
5757
</ClInclude>
58-
<ClInclude Include="Utils\NonCopyableAndNonMovable.h">
59-
<Filter>Utils</Filter>
60-
</ClInclude>
6158
<ClInclude Include="Utils\WinApiUtils.h">
6259
<Filter>Utils</Filter>
6360
</ClInclude>

src/DOpusScriptingExtensions/ExifTool/ExifToolWrapper.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
class ExifToolWrapper : NonCopyableAndNonMovable {
3+
class ExifToolWrapper : boost::noncopyable {
44
public:
55
static ExifToolWrapper* GetInstance() {
66
static ExifToolWrapper instance;
@@ -39,10 +39,12 @@ class ExifToolWrapper : NonCopyableAndNonMovable {
3939
THROW_WEXCEPTION(L"File is a directory '{}'", filePath);
4040
}
4141

42+
ValidateExifToolTagNames(tagNames);
43+
4244
ioCtx.restart();
4345

4446
boost::asio::write(stdInPipe, boost::asio::buffer(
45-
ToUtf8(filePath) + "\n-decimal\n-json\n-long\n-groupNames:0:1\n-echo4\n{readyErr}\n" + toCommandLineArgs(tagNames) + "-execute\n"));
47+
ToUtf8(filePath) + "\n-decimal\n-json\n-long\n-groupNames:0:1\n-echo4\n{readyErr}\n" + ToCommandLineArgs(tagNames) + "-execute\n"));
4648

4749
static const std::string readyStr = "{ready}\r\n";
4850
static const std::string readyErrStr = "{readyErr}\r\n";
@@ -63,20 +65,31 @@ class ExifToolWrapper : NonCopyableAndNonMovable {
6365
private:
6466
ExifToolWrapper() = default;
6567

66-
std::string toCommandLineArgs(const std::vector<std::string>& tagNames) {
68+
std::string ToCommandLineArgs(const std::vector<std::string>& tagNames) {
6769
std::string result;
6870
for (const auto& tag : tagNames) {
6971
result += std::format("-{}\n", tag);
7072
}
7173
return result;
7274
}
7375

76+
void ValidateExifToolTagNames(const std::vector<std::string>& tagNames) {
77+
// ExifTags must be in the format "Group0:TagName"
78+
static const std::regex exifTagFormat(R"(^[A-Za-z0-9]+:[A-Za-z0-9]+$)");
79+
80+
for (const auto& tagName : tagNames) {
81+
if(!std::regex_match(tagName, exifTagFormat)) {
82+
THROW_WEXCEPTION(L"ExifTool tag name '{}' is incorrect. The tag name should be in format 'Group0:TagName', for example 'AIFF:FormatVersionTime'", ToWide(tagName));
83+
}
84+
}
85+
}
86+
7487
boost::asio::io_context ioCtx;
7588
boost::asio::readable_pipe stdOutPipe{ ioCtx }, stdErrPipe{ ioCtx };
7689
boost::asio::writable_pipe stdInPipe{ ioCtx };
7790
boost::process::v2::process proc{
7891
ioCtx,
79-
boost::dll::this_line_location().parent_path() / L"exiftool" / L"exiftool(-k).exe",
92+
boost::dll::this_line_location().parent_path() / L"exiftool" / L"exiftool.exe",
8093
{ "-stay_open", "true", "-@", "-" },
8194
boost::process::v2::process_stdio{ stdInPipe, stdOutPipe, stdErrPipe },
8295
boost::process::v2::windows::show_window_hide };

src/DOpusScriptingExtensions/FileMimeTypeDetector/LibMagicWrapper.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
class LibMagicWrapper : NonCopyableAndNonMovable {
3+
class LibMagicWrapper : boost::noncopyable {
44
public:
55
static const LibMagicWrapper* GetSingleInstance() {
66
static const LibMagicWrapper instance{ MAGIC_MIME, boost::dll::this_line_location().parent_path() / L"magic.mgc" };

src/DOpusScriptingExtensions/Utils/NonCopyableAndNonMovable.h

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/DOpusScriptingExtensions/pch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@
3131
#include <boost/locale.hpp>
3232
#include <boost/asio.hpp>
3333
#include <boost/dll.hpp>
34+
#include <boost/noncopyable.hpp>
3435
#include <magic.h>
3536
#include <MediaInfo/MediaInfo.h>

0 commit comments

Comments
 (0)