Skip to content

Commit 3cdbe3e

Browse files
committed
Reorganize source code and fix ambiguous class name
1 parent c43a6b3 commit 3cdbe3e

9 files changed

+104
-122
lines changed

src/CMakeLists.txt

+2-86
Original file line numberDiff line numberDiff line change
@@ -26,96 +26,12 @@ endif()
2626

2727
add_subdirectory(util)
2828
add_subdirectory(updateinformation)
29-
add_subdirectory(appimage)
30-
31-
# core library
32-
add_library(libappimageupdate SHARED
33-
${PROJECT_SOURCE_DIR}/include/appimage/update.h
34-
updater.cpp
35-
)
36-
# since the target is called libsomething, one doesn't need CMake's additional lib prefix
37-
set_target_properties(libappimageupdate
38-
PROPERTIES
39-
PREFIX ""
40-
PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/appimage/update.h
41-
)
42-
# link thread libraries
43-
target_link_libraries(libappimageupdate
44-
PRIVATE ${CMAKE_THREAD_LIBS_INIT}
45-
PRIVATE ${CPR_LIBRARIES}
46-
PRIVATE util
47-
PRIVATE appimage
48-
${ZSYNC2_LINK_TYPE} ${ZSYNC2_LIBRARY_NAME}
49-
)
50-
# include directories, publicly
51-
target_include_directories(libappimageupdate
52-
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
53-
PUBLIC $<INSTALL_INTERFACE:include>
54-
)
55-
set_target_properties(libappimageupdate PROPERTIES INSTALL_RPATH "\$ORIGIN/")
56-
57-
58-
# core library
59-
add_library(libappimageupdate_static STATIC
60-
${PROJECT_SOURCE_DIR}/include/appimage/update.h
61-
updater.cpp
62-
)
63-
# since the target is called libsomething, one doesn't need CMake's additional lib prefix
64-
set_target_properties(libappimageupdate_static
65-
PROPERTIES
66-
PREFIX ""
67-
OUTPUT_NAME "libappimageupdate"
68-
PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/appimage/update.h
69-
)
70-
# link thread libraries
71-
target_link_libraries(libappimageupdate_static
72-
PRIVATE appimage
73-
PRIVATE ${CMAKE_THREAD_LIBS_INIT}
74-
PRIVATE ${CPR_LIBRARIES}
75-
PRIVATE util
76-
${ZSYNC2_LINK_TYPE} ${ZSYNC2_LIBRARY_NAME}
77-
)
78-
# include directories, publicly
79-
target_include_directories(libappimageupdate_static
80-
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
81-
PUBLIC $<INSTALL_INTERFACE:include>
82-
)
83-
29+
add_subdirectory(updater)
8430

8531
if(NOT BUILD_LIBAPPIMAGEUPDATE_ONLY)
86-
# CLI application
87-
add_executable(appimageupdatetool main.cpp)
88-
# link to core lib
89-
target_link_libraries(appimageupdatetool libappimageupdate util)
90-
if(NOT USE_SYSTEM_ZSYNC2)
91-
target_link_libraries(appimageupdatetool ${ZSYNC2_LIBRARY_NAME})
92-
endif()
93-
94-
# set up rpath
95-
set_target_properties(libappimageupdate libappimageupdate_static PROPERTIES INSTALL_RPATH "\$ORIGIN")
96-
set_target_properties(appimageupdatetool PROPERTIES INSTALL_RPATH "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
32+
add_subdirectory(cli)
9733
endif()
9834

99-
# install targets
100-
install(
101-
TARGETS libappimageupdate
102-
EXPORT AppImageUpdateTargets
103-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT LIBAPPIMAGEUPDATE
104-
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/appimage COMPONENT LIBAPPIMAGEUPDATE-DEV
105-
)
106-
install(
107-
TARGETS libappimageupdate_static
108-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT LIBAPPIMAGEUPDATE
109-
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/appimage COMPONENT LIBAPPIMAGEUPDATE-DEV
110-
)
111-
if(NOT BUILD_LIBAPPIMAGEUPDATE_ONLY)
112-
install(
113-
TARGETS appimageupdatetool
114-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT APPIMAGEUPDATETOOL
115-
)
116-
endif()
117-
118-
11935
# include Qt UI
12036
if(BUILD_QT_UI)
12137
add_subdirectory(qt-ui)

src/appimage/CMakeLists.txt

-17
This file was deleted.

src/cli/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# CLI application
2+
add_executable(appimageupdatetool main.cpp)
3+
# link to core lib
4+
target_link_libraries(appimageupdatetool libappimageupdate util)
5+
if(NOT USE_SYSTEM_ZSYNC2)
6+
target_link_libraries(appimageupdatetool ${ZSYNC2_LIBRARY_NAME})
7+
endif()
8+
9+
# set up rpath
10+
set_target_properties(appimageupdatetool PROPERTIES INSTALL_RPATH "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
11+
12+
# install target
13+
install(
14+
TARGETS appimageupdatetool
15+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT APPIMAGEUPDATETOOL
16+
)
File renamed without changes.

src/updater/CMakeLists.txt

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# core library
2+
add_library(libappimageupdate SHARED
3+
${PROJECT_SOURCE_DIR}/include/appimage/update.h
4+
updater.cpp
5+
)
6+
# since the target is called libsomething, one doesn't need CMake's additional lib prefix
7+
set_target_properties(libappimageupdate
8+
PROPERTIES
9+
PREFIX ""
10+
PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/appimage/update.h
11+
)
12+
# link thread libraries
13+
target_link_libraries(libappimageupdate
14+
PRIVATE ${CMAKE_THREAD_LIBS_INIT}
15+
PRIVATE ${CPR_LIBRARIES}
16+
PRIVATE util
17+
PRIVATE updateinformation
18+
${ZSYNC2_LINK_TYPE} ${ZSYNC2_LIBRARY_NAME}
19+
)
20+
# include directories, publicly
21+
target_include_directories(libappimageupdate
22+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
23+
PUBLIC $<INSTALL_INTERFACE:include>
24+
)
25+
set_target_properties(libappimageupdate PROPERTIES INSTALL_RPATH "\$ORIGIN/")
26+
27+
28+
# core library
29+
add_library(libappimageupdate_static STATIC
30+
${PROJECT_SOURCE_DIR}/include/appimage/update.h
31+
updater.cpp
32+
)
33+
# since the target is called libsomething, one doesn't need CMake's additional lib prefix
34+
set_target_properties(libappimageupdate_static
35+
PROPERTIES
36+
PREFIX ""
37+
OUTPUT_NAME "libappimageupdate"
38+
PUBLIC_HEADER ${PROJECT_SOURCE_DIR}/include/appimage/update.h
39+
)
40+
# link thread libraries
41+
target_link_libraries(libappimageupdate_static
42+
PRIVATE ${CMAKE_THREAD_LIBS_INIT}
43+
PRIVATE ${CPR_LIBRARIES}
44+
PRIVATE util
45+
PRIVATE updateinformation
46+
${ZSYNC2_LINK_TYPE} ${ZSYNC2_LIBRARY_NAME}
47+
)
48+
# include directories, publicly
49+
target_include_directories(libappimageupdate_static
50+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
51+
PUBLIC $<INSTALL_INTERFACE:include>
52+
)
53+
# set up rpath
54+
set_target_properties(libappimageupdate libappimageupdate_static PROPERTIES INSTALL_RPATH "\$ORIGIN")
55+
56+
# install targets
57+
install(
58+
TARGETS libappimageupdate
59+
EXPORT AppImageUpdateTargets
60+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT LIBAPPIMAGEUPDATE
61+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/appimage COMPONENT LIBAPPIMAGEUPDATE-DEV
62+
)
63+
install(
64+
TARGETS libappimageupdate_static
65+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT LIBAPPIMAGEUPDATE
66+
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/appimage COMPONENT LIBAPPIMAGEUPDATE-DEV
67+
)

src/updater.cpp renamed to src/updater/updater.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// local headers
1818
#include "appimage/update.h"
1919
#include "updateinformation/updateinformation.h"
20-
#include "appimage/appimage.h"
20+
#include "util/updatableappimage.h"
2121
#include "util/util.h"
2222
#include "zsutil.h"
2323

@@ -42,7 +42,7 @@ namespace appimage::update {
4242
{};
4343

4444
public:
45-
AppImage appImage;
45+
UpdatableAppImage appImage;
4646

4747
// we call this "raw" update information to highlight the difference between strings and the new
4848
// UpdateInformation infrastructure
@@ -388,14 +388,14 @@ namespace appimage::update {
388388
return VALIDATION_FAILED;
389389
}
390390

391-
AppImage newAppImage(pathToNewAppImage);
391+
UpdatableAppImage newAppImage(pathToNewAppImage);
392392

393393
auto pathToOldAppImage = abspath(d->appImage.path());
394394
if (pathToOldAppImage == pathToNewAppImage) {
395395
pathToOldAppImage = pathToNewAppImage + ".zs-old";
396396
}
397397

398-
AppImage oldAppImage(pathToOldAppImage);
398+
UpdatableAppImage oldAppImage(pathToOldAppImage);
399399

400400
auto oldSignature = oldAppImage.readSignature();
401401
auto newSignature = newAppImage.readSignature();

src/util/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.19)
33

44
add_library(util STATIC
55
util.cpp
6-
util.h
6+
updatableappimage.cpp
77
)
88
# include the complete source to force the use of project-relative include paths
99
target_include_directories(util

src/appimage/appimage.cpp renamed to src/util/updatableappimage.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <zshash.h>
44

55
// local headers
6-
#include "appimage.h"
6+
#include "updatableappimage.h"
77
#include "updateinformation/updateinformation.h"
88
#include "util/util.h"
99

@@ -12,20 +12,20 @@ namespace appimage::update {
1212
using namespace util;
1313
using namespace zsync2;
1414

15-
void AppImage::assertIfstreamGood(const std::ifstream& ifs) const {
15+
void UpdatableAppImage::assertIfstreamGood(const std::ifstream& ifs) const {
1616
if (!ifs || !ifs.good()) {
1717
throw AppImageError("Error while opening/accessing/reading from AppImage: " + _path);
1818
}
1919
}
2020

21-
std::ifstream AppImage::_open() const {
21+
std::ifstream UpdatableAppImage::_open() const {
2222
// check whether file exists
2323
std::ifstream ifs(_path);
2424
assertIfstreamGood(ifs);
2525
return ifs;
2626
}
2727

28-
bool AppImage::_hasElfMagicValue(std::ifstream& ifs) const {
28+
bool UpdatableAppImage::_hasElfMagicValue(std::ifstream& ifs) const {
2929
static constexpr int elfMagicPos = 0;
3030
static const std::string elfMagicValue = "\7ELF";
3131

@@ -40,7 +40,7 @@ namespace appimage::update {
4040
return elfMagicPosData.data() == elfMagicValue;
4141
}
4242

43-
bool AppImage::_hasIsoMagicValue(std::ifstream& ifs) const {
43+
bool UpdatableAppImage::_hasIsoMagicValue(std::ifstream& ifs) const {
4444
static constexpr int isoMagicPos = 32769;
4545
static const std::string isoMagicValue = "CD001";
4646

@@ -55,13 +55,13 @@ namespace appimage::update {
5555
return isoMagicPosData.data() == isoMagicValue;
5656
}
5757

58-
AppImage::AppImage(std::string path) : _path(std::move(path)) {}
58+
UpdatableAppImage::UpdatableAppImage(std::string path) : _path(std::move(path)) {}
5959

60-
std::string AppImage::path() const {
60+
std::string UpdatableAppImage::path() const {
6161
return _path;
6262
}
6363

64-
int AppImage::appImageType() const {
64+
int UpdatableAppImage::appImageType() const {
6565
auto ifs = _open();
6666

6767
// read magic number
@@ -97,7 +97,7 @@ namespace appimage::update {
9797
throw AppImageError("Unknown AppImage type or not an AppImage");
9898
}
9999

100-
std::string AppImage::readSignature() const {
100+
std::string UpdatableAppImage::readSignature() const {
101101
const auto type = appImageType();
102102

103103
if (type != 2) {
@@ -107,7 +107,7 @@ namespace appimage::update {
107107
return readElfSection(_path, ".sha256_sig");
108108
}
109109

110-
std::string AppImage::readSigningKey() const {
110+
std::string UpdatableAppImage::readSigningKey() const {
111111
const auto type = appImageType();
112112

113113
if (type != 2) {
@@ -117,7 +117,7 @@ namespace appimage::update {
117117
return readElfSection(_path, ".sig_key");
118118
}
119119

120-
std::string AppImage::readRawUpdateInformation() const {
120+
std::string UpdatableAppImage::readRawUpdateInformation() const {
121121
auto ifs = _open();
122122

123123
int type;
@@ -156,7 +156,7 @@ namespace appimage::update {
156156
throw AppImageError("Reading update information not supported for type " + std::to_string(type));
157157
}
158158

159-
std::string AppImage::calculateHash() const {
159+
std::string UpdatableAppImage::calculateHash() const {
160160
// read offset and length of signature section to skip it later
161161
unsigned long sigOffset = 0, sigLength = 0;
162162
unsigned long keyOffset = 0, keyLength = 0;

src/appimage/appimage.h renamed to src/util/updatableappimage.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace appimage::update {
99
using std::runtime_error::runtime_error;
1010
};
1111

12-
class AppImage {
12+
class UpdatableAppImage {
1313
private:
1414
std::string _path;
1515

@@ -23,7 +23,7 @@ namespace appimage::update {
2323
bool _hasIsoMagicValue(std::ifstream& ifs) const;
2424

2525
public:
26-
explicit AppImage(std::string path);
26+
explicit UpdatableAppImage(std::string path);
2727

2828
[[nodiscard]] std::string path() const;
2929

0 commit comments

Comments
 (0)