Skip to content

Commit d5fa577

Browse files
committed
Use version information from config instead.
1 parent 587af6b commit d5fa577

File tree

1 file changed

+8
-27
lines changed

1 file changed

+8
-27
lines changed

src/Licence.cpp

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
void License::write(const Options &options,const Config &config,const wstring name)
2424
{
25+
auto& version=config.version();
26+
if (version.isEmpty())
27+
throwException(L"Missing version information for: " + config.name());
28+
2529
const auto targetDirectory=options.licenseArtifactsDirectory();
2630
filesystem::create_directories(targetDirectory);
2731

@@ -30,34 +34,11 @@ void License::write(const Options &options,const Config &config,const wstring na
3034
if (!sourceLicenseFile)
3135
throwException(L"Failed to open license file: " + sourceFileName);
3236

33-
const auto path=filesystem::path(sourceFileName).parent_path();
34-
auto versionFileName=path.wstring() + L"\\.ImageMagick\\ImageMagick.version.h";
35-
auto projectName=path.filename().wstring();
36-
if (!filesystem::exists(versionFileName))
37-
{
38-
versionFileName=options.rootDirectory + config.directory() + L".ImageMagick\\ImageMagick.version.h";
39-
projectName=name;
40-
}
41-
42-
wofstream licenseFile(targetDirectory + projectName + L".txt");
43-
wifstream versionFile(versionFileName);
44-
if (versionFile)
45-
{
46-
wstring
47-
line;
37+
wstring content((std::istreambuf_iterator<wchar_t>(sourceLicenseFile)),std::istreambuf_iterator<wchar_t>());
4838

49-
getline(versionFile,line);
50-
getline(versionFile,line);
51-
if (!startsWith(line,L"#define DELEGATE_VERSION_STRING "))
52-
throwException(L"Invalid version file: " + versionFileName);
53-
line=line.substr(33,line.length() - 34);
54-
licenseFile << L"[ " << projectName << L" " << line << L" ]" << endl << endl;
55-
}
56-
else
57-
{
58-
licenseFile << L"[ " << projectName << L" ]" << endl << endl;
59-
}
60-
licenseFile << sourceLicenseFile.rdbuf() << endl;
39+
wofstream licenseFile(targetDirectory + config.name() + L".txt");
40+
licenseFile << L"[ " << config.productName() << L" " << version.fullVersion() << L" (" << config.releaseDate() << L") ]" << endl << endl;
41+
licenseFile << trim(content) << endl;
6142
}
6243

6344
void License::writeNonWindowsLicenses(const Options &options)

0 commit comments

Comments
 (0)