|
| 1 | +/* |
| 2 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | +% % |
| 4 | +% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization % |
| 5 | +% dedicated to making software imaging solutions freely available. % |
| 6 | +% % |
| 7 | +% You may not use this file except in compliance with the License. You may % |
| 8 | +% obtain a copy of the License at % |
| 9 | +% % |
| 10 | +% http://www.imagemagick.org/script/license.php % |
| 11 | +% % |
| 12 | +% Unless required by applicable law or agreed to in writing, software % |
| 13 | +% distributed under the License is distributed on an "AS IS" BASIS, % |
| 14 | +% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 15 | +% See the License for the specific language governing permissions and % |
| 16 | +% limitations under the License. % |
| 17 | +% % |
| 18 | +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 19 | +*/ |
| 20 | + |
| 21 | +#include "License.h" |
| 22 | + |
| 23 | +void License::write(const Options &options,const Config &config,const wstring name) |
| 24 | +{ |
| 25 | + const auto targetDirectory=options.rootDirectory + L"Artifacts\\license\\"; |
| 26 | + filesystem::create_directories(targetDirectory); |
| 27 | + |
| 28 | + wofstream licenseFile(targetDirectory + name + L".txt"); |
| 29 | + for (const auto& license : config.licenses()) |
| 30 | + { |
| 31 | + const auto sourceFileName=options.rootDirectory + config.directory() + license; |
| 32 | + wifstream sourceLicenseFile(sourceFileName); |
| 33 | + if (!sourceLicenseFile) |
| 34 | + throwException(L"Failed to open license file: " + sourceFileName); |
| 35 | + |
| 36 | + auto versionFileName=options.rootDirectory + config.directory() + L".ImageMagick\\ImageMagick.version.h"; |
| 37 | + auto projectName=name; |
| 38 | + if (!filesystem::exists(versionFileName)) |
| 39 | + { |
| 40 | + const auto configDirectory=sourceFileName.substr(0,sourceFileName.find_last_of(L"\\")); |
| 41 | + versionFileName=configDirectory + L"\\.ImageMagick\\ImageMagick.version.h"; |
| 42 | + projectName=configDirectory.substr(configDirectory.find_last_of(L"\\") + 1); |
| 43 | + } |
| 44 | + |
| 45 | + wifstream versionFile(versionFileName); |
| 46 | + if (versionFile) |
| 47 | + { |
| 48 | + wstring |
| 49 | + line; |
| 50 | + |
| 51 | + getline(versionFile,line); |
| 52 | + getline(versionFile,line); |
| 53 | + if (!startsWith(line,L"#define DELEGATE_VERSION_STRING ")) |
| 54 | + throwException(L"Invalid version file: " + versionFileName); |
| 55 | + line=line.substr(33,line.length() - 34); |
| 56 | + licenseFile << L"[ " << projectName << L" " << line << L" ]" << endl << endl; |
| 57 | + } |
| 58 | + else |
| 59 | + { |
| 60 | + licenseFile << L"[ " << projectName << L" ]" << endl << endl; |
| 61 | + } |
| 62 | + licenseFile << sourceLicenseFile.rdbuf() << endl; |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +void License::writeNonWindowsLicenses(const Options &options) |
| 67 | +{ |
| 68 | + auto directory=L"Dependencies\\NonWindowsDependencies\\"; |
| 69 | + if (!filesystem::exists(options.rootDirectory + directory)) |
| 70 | + directory=L"NonWindowsDependencies\\"; |
| 71 | + |
| 72 | + if (!filesystem::exists(options.rootDirectory + directory)) |
| 73 | + return; |
| 74 | + |
| 75 | + for (const auto& entry : filesystem::directory_iterator(options.rootDirectory + directory)) |
| 76 | + { |
| 77 | + if (!entry.is_directory()) |
| 78 | + continue; |
| 79 | + |
| 80 | + auto name=entry.path().filename().wstring(); |
| 81 | + auto projectDirectory=directory + name + L"\\"; |
| 82 | + auto configFile=options.rootDirectory + projectDirectory + L".ImageMagick\\Config.txt"; |
| 83 | + auto config=Config::load(name,projectDirectory,configFile); |
| 84 | + |
| 85 | + License::write(options,config,name); |
| 86 | + } |
| 87 | +} |
0 commit comments