Skip to content

Commit 14da43c

Browse files
Ported createClientSource to C++
1 parent 064a5ca commit 14da43c

5 files changed

Lines changed: 192 additions & 138 deletions

File tree

Artifacts/build_client_clean.bat

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ git rev-parse --verify --short HEAD >"%TOOLBUILDDIR%\githash.txt"
4848
git log -n 1 --format="%%H" -- "Client" >"%TOOLBUILDDIR%\clientdirhash.txt"
4949
cmake -S ..\.. -B "%TOOLBUILDDIR%"
5050
cmake --build "%TOOLBUILDDIR%" --target create_client_dist --config Release
51+
cmake --build "%TOOLBUILDDIR%" --target create_client_source --config Release
5152
"%TOOLBUILDDIR%\DevPackage\Framework\create_client_dist.exe" dist ..\..\Artifacts\clientdist\clientpackage.zip
5253

53-
go run ..\..\BuildScripts\createClientSource.go . ..\..\Artifacts\clientdist\clientsourcepackage.zip
54+
"%TOOLBUILDDIR%\DevPackage\Framework\create_client_source.exe" . ..\..\Artifacts\clientdist\clientsourcepackage.zip
5455

5556
if "%1" neq "NOPAUSE" (
5657
pause

Artifacts/build_client_clean.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ git rev-parse --verify --short HEAD > "$TOOLBUILDDIR/githash.txt"
4545
git log -n 1 --format="%H" -- "Client" > "$TOOLBUILDDIR/clientdirhash.txt"
4646
cmake -S ../.. -B "$TOOLBUILDDIR"
4747
cmake --build "$TOOLBUILDDIR" --target create_client_dist --config Release
48+
cmake --build "$TOOLBUILDDIR" --target create_client_source --config Release
4849
"$TOOLBUILDDIR/DevPackage/Framework/create_client_dist" dist ../../Artifacts/clientdist/clientpackage.zip
4950

50-
go run ../../BuildScripts/createClientSource.go . ../../Artifacts/clientdist/clientsourcepackage.zip
51+
"$TOOLBUILDDIR/DevPackage/Framework/create_client_source" . ../../Artifacts/clientdist/clientsourcepackage.zip
5152

5253
echo
5354
echo "Created packages in Artifacts/clientdist/:"
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*++
2+
3+
Copyright (C) 2024 Autodesk Inc.
4+
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the Autodesk Inc. nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL AUTODESK INC. BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28+
29+
*/
30+
31+
32+
#include <string>
33+
#include <iostream>
34+
#include <memory>
35+
#include <exception>
36+
#include <vector>
37+
#include <algorithm>
38+
#include <filesystem>
39+
40+
#include "common_importstream_native.hpp"
41+
#include "common_exportstream_native.hpp"
42+
#include "common_portablezipwriter.hpp"
43+
44+
static void writeUsage()
45+
{
46+
std::cout << "Please start with createClientSource <inputpath> <outputfile>" << std::endl;
47+
}
48+
49+
static void addFileToZip(AMCCommon::CPortableZIPWriter& zipWriter, const std::string& sSourcePath, const std::string& sZipPath)
50+
{
51+
AMCCommon::CImportStream_Native importStream(sSourcePath);
52+
auto pEntryStream = zipWriter.createEntry(sZipPath, 0);
53+
54+
const uint64_t nBufferSize = 1024 * 64;
55+
std::vector<uint8_t> buffer;
56+
buffer.resize(nBufferSize);
57+
58+
uint64_t nTotalSize = importStream.retrieveSize();
59+
uint64_t nRemaining = nTotalSize;
60+
61+
while (nRemaining > 0) {
62+
uint64_t nChunk = std::min<uint64_t>(nRemaining, nBufferSize);
63+
uint64_t nReadBytes = importStream.readBuffer(buffer.data(), nChunk, true);
64+
if (nReadBytes != nChunk)
65+
throw std::runtime_error("could not read full data from " + sSourcePath);
66+
67+
pEntryStream->writeBuffer(buffer.data(), nReadBytes);
68+
nRemaining -= nReadBytes;
69+
}
70+
71+
zipWriter.closeEntry();
72+
}
73+
74+
static void addSourceFolder(AMCCommon::CPortableZIPWriter& zipWriter, const std::filesystem::path& inputPath, const std::string& sPrefix)
75+
{
76+
std::filesystem::path folderPath = inputPath / "src" / sPrefix;
77+
if (!std::filesystem::exists(folderPath) || !std::filesystem::is_directory(folderPath))
78+
throw std::runtime_error("source folder does not exist: " + folderPath.u8string());
79+
80+
for (auto const& entry : std::filesystem::recursive_directory_iterator(folderPath)) {
81+
if (!entry.is_regular_file())
82+
continue;
83+
84+
std::string sFileName = entry.path().filename().u8string();
85+
if (sFileName.empty())
86+
continue;
87+
88+
std::string sZipPath = sPrefix + "/" + sFileName;
89+
std::string sSourcePath = entry.path().u8string();
90+
91+
std::cout << "adding " << sZipPath << "..." << std::endl;
92+
addFileToZip(zipWriter, sSourcePath, sZipPath);
93+
}
94+
}
95+
96+
int main(int argc, char* argv[])
97+
{
98+
try
99+
{
100+
if (argc < 3) {
101+
writeUsage();
102+
return 1;
103+
}
104+
105+
std::filesystem::path inputPath = std::filesystem::path(argv[1]);
106+
std::string sOutputFileName = argv[2];
107+
108+
if (!std::filesystem::exists(inputPath) || !std::filesystem::is_directory(inputPath))
109+
throw std::runtime_error("input directory does not exist: " + inputPath.u8string());
110+
111+
AMCCommon::PExportStream pExportStream = std::make_shared<AMCCommon::CExportStream_Native>(sOutputFileName);
112+
AMCCommon::CPortableZIPWriter zipWriter(pExportStream, true);
113+
114+
addSourceFolder(zipWriter, inputPath, "common");
115+
addSourceFolder(zipWriter, inputPath, "modules");
116+
addSourceFolder(zipWriter, inputPath, "dialogs");
117+
118+
addFileToZip(zipWriter, (inputPath / "package.json").u8string(), "packages/package.json");
119+
addFileToZip(zipWriter, (inputPath / "package-lock.json").u8string(), "packages/package-lock.json");
120+
121+
zipWriter.writeDirectory();
122+
return 0;
123+
}
124+
catch (std::exception& E)
125+
{
126+
std::cout << "Fatal error: " << E.what() << std::endl;
127+
return -1;
128+
}
129+
catch (...)
130+
{
131+
std::cout << "Unhandled fatal exception!" << std::endl;
132+
return -1;
133+
}
134+
}

BuildScripts/createClientSource.go

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

CMakeLists.txt

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,7 @@ endif()
11071107

11081108
file(GLOB CREATE_CLIENT_DIST_SRC
11091109
${CMAKE_CURRENT_SOURCE_DIR}/BuildScripts/createClientDist.cpp
1110+
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_utils.cpp
11101111
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_importstream_native.cpp
11111112
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_exportstream_native.cpp
11121113
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_exportstream_zip.cpp
@@ -1151,6 +1152,59 @@ endif()
11511152

11521153

11531154

1155+
#[[++
1156+
1157+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1158+
+ create_client_source Target
1159+
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1160+
1161+
]]
1162+
1163+
1164+
file(GLOB CREATE_CLIENT_SOURCE_SRC
1165+
${CMAKE_CURRENT_SOURCE_DIR}/BuildScripts/createClientSource.cpp
1166+
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_importstream_native.cpp
1167+
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_exportstream_native.cpp
1168+
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_exportstream_zip.cpp
1169+
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_portablezipwriter.cpp
1170+
${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common/common_portablezipwriterentry.cpp
1171+
${CMAKE_CURRENT_SOURCE_DIR}/Libraries/crossguid/guid.cpp
1172+
${LIBMC_SRC_DEP_ZLIB}
1173+
)
1174+
1175+
add_executable(create_client_source ${CREATE_CLIENT_SOURCE_SRC})
1176+
1177+
target_include_directories(create_client_source PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Implementation/Common)
1178+
target_include_directories(create_client_source PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/Libraries)
1179+
target_include_directories(create_client_source PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/)
1180+
1181+
set_target_properties(create_client_source
1182+
PROPERTIES
1183+
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/DevPackage/Framework"
1184+
RUNTIME_OUTPUT_DIRECTORY_DEBUG "${PROJECT_BINARY_DIR}/DevPackage/Framework"
1185+
RUNTIME_OUTPUT_DIRECTORY_RELEASE "${PROJECT_BINARY_DIR}/DevPackage/Framework"
1186+
LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/DevPackage/Framework"
1187+
1188+
OUTPUT_NAME "create_client_source"
1189+
1190+
VS_DEBUGGER_WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/Output"
1191+
)
1192+
1193+
1194+
if(WIN32)
1195+
target_link_libraries(create_client_source shlwapi.lib)
1196+
target_link_libraries(create_client_source ws2_32.lib)
1197+
endif(WIN32)
1198+
1199+
if(UNIX)
1200+
if(NOT LIBUUID_PATH)
1201+
message(FATAL_ERROR "libuuid not found")
1202+
endif()
1203+
target_link_libraries(create_client_source ${LIBUUID_PATH})
1204+
endif()
1205+
1206+
1207+
11541208
#[[++
11551209
11561210
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

0 commit comments

Comments
 (0)