Skip to content

Commit 0d660c7

Browse files
committed
fixup wstring functions to use fs::path
Signed-off-by: Rosen Penev <[email protected]>
1 parent 9d7c5af commit 0d660c7

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

include/exiv2/image.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class EXIV2API ImageFactory {
527527
*/
528528
static BasicIo::UniquePtr createIo(const std::string& path, bool useCurl = true);
529529
#ifdef _WIN32
530-
static BasicIo::UniquePtr createIo(const std::wstring& path);
530+
static BasicIo::UniquePtr createIo(const std::wstring& path, bool useCurl = true);
531531
#endif
532532
/*!
533533
@brief Create an Image subclass of the appropriate type by reading
@@ -544,7 +544,7 @@ class EXIV2API ImageFactory {
544544
*/
545545
static Image::UniquePtr open(const std::string& path, bool useCurl = true);
546546
#ifdef _WIN32
547-
static Image::UniquePtr open(const std::wstring& path);
547+
static Image::UniquePtr open(const std::wstring& path, bool useCurl = true);
548548
#endif
549549
/*!
550550
@brief Create an Image subclass of the appropriate type by reading
@@ -619,6 +619,9 @@ class EXIV2API ImageFactory {
619619
@return %Image type or Image::none if the type is not recognized.
620620
*/
621621
static ImageType getType(const std::string& path);
622+
#ifdef _WIN32
623+
static ImageType getType(const std::wstring& path);
624+
#endif
622625
/*!
623626
@brief Returns the image type of the provided data buffer.
624627
@param data Pointer to a data buffer containing an image. The contents

src/image.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,17 @@ ImageType ImageFactory::getType([[maybe_unused]] const std::string& path) {
763763
#endif
764764
}
765765

766+
#ifdef _WIN32
767+
ImageType ImageFactory::getType([[maybe_unused]] const std::wstring& path) {
768+
#ifdef EXV_ENABLE_FILESYSTEM
769+
FileIo fileIo(path);
770+
return getType(fileIo);
771+
#else
772+
return ImageType::none;
773+
#endif
774+
}
775+
#endif
776+
766777
ImageType ImageFactory::getType(const byte* data, size_t size) {
767778
MemIo memIo(data, size);
768779
return getType(memIo);
@@ -806,7 +817,7 @@ BasicIo::UniquePtr ImageFactory::createIo(const std::string& path, [[maybe_unuse
806817
} // ImageFactory::createIo
807818

808819
#ifdef _WIN32
809-
BasicIo::UniquePtr ImageFactory::createIo(const std::wstring& path) {
820+
BasicIo::UniquePtr ImageFactory::createIo(const std::wstring& path, bool) {
810821
#ifdef EXV_ENABLE_FILESYSTEM
811822
return std::make_unique<FileIo>(path);
812823
#else
@@ -823,8 +834,8 @@ Image::UniquePtr ImageFactory::open(const std::string& path, bool useCurl) {
823834
}
824835

825836
#ifdef _WIN32
826-
Image::UniquePtr ImageFactory::open(const std::wstring& path) {
827-
auto image = open(ImageFactory::createIo(path)); // may throw
837+
Image::UniquePtr ImageFactory::open(const std::wstring& path, bool useCurl) {
838+
auto image = open(ImageFactory::createIo(path, useCurl)); // may throw
828839
if (!image) {
829840
char t[1024];
830841
WideCharToMultiByte(CP_UTF8, 0, path.c_str(), -1, t, 1024, nullptr, nullptr);

unitTests/test_ImageFactory.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,45 +100,45 @@ TEST(TheImageFactory, cannotCreateInstancesForSomeTypesInFiles) {
100100
TEST(TheImageFactory, loadInstancesDifferentImageTypes) {
101101
fs::path testData(TESTDATA_PATH);
102102

103-
std::string imagePath = (testData / "DSC_3079.jpg").string();
103+
fs::path imagePath = testData / "DSC_3079.jpg";
104104
EXPECT_EQ(ImageType::jpeg, ImageFactory::getType(imagePath));
105105
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
106106

107-
imagePath = (testData / "exiv2-bug1108.exv").string();
107+
imagePath = testData / "exiv2-bug1108.exv";
108108
EXPECT_EQ(ImageType::exv, ImageFactory::getType(imagePath));
109109
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
110110

111-
imagePath = (testData / "exiv2-canon-powershot-s40.crw").string();
111+
imagePath = testData / "exiv2-canon-powershot-s40.crw";
112112
EXPECT_EQ(ImageType::crw, ImageFactory::getType(imagePath));
113113
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
114114

115-
imagePath = (testData / "exiv2-bug1044.tif").string();
115+
imagePath = testData / "exiv2-bug1044.tif";
116116
EXPECT_EQ(ImageType::tiff, ImageFactory::getType(imagePath));
117117
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
118118

119119
#ifdef EXV_HAVE_LIBZ
120-
imagePath = (testData / "exiv2-bug1074.png").string();
120+
imagePath = testData / "exiv2-bug1074.png";
121121
EXPECT_EQ(ImageType::png, ImageFactory::getType(imagePath));
122122
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
123123
#endif
124124

125-
imagePath = (testData / "BlueSquare.xmp").string();
125+
imagePath = testData / "BlueSquare.xmp";
126126
EXPECT_EQ(ImageType::xmp, ImageFactory::getType(imagePath));
127127
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
128128

129-
imagePath = (testData / "exiv2-photoshop.psd").string();
129+
imagePath = testData / "exiv2-photoshop.psd";
130130
EXPECT_EQ(ImageType::psd, ImageFactory::getType(imagePath));
131131
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
132132

133-
imagePath = (testData / "cve_2017_1000126_stack-oob-read.webp").string();
133+
imagePath = testData / "cve_2017_1000126_stack-oob-read.webp";
134134
EXPECT_EQ(ImageType::webp, ImageFactory::getType(imagePath));
135135
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
136136

137-
imagePath = (testData / "imagemagick.pgf").string();
137+
imagePath = testData / "imagemagick.pgf";
138138
EXPECT_EQ(ImageType::pgf, ImageFactory::getType(imagePath));
139139
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
140140

141-
imagePath = (testData / "Reagan.jp2").string();
141+
imagePath = testData / "Reagan.jp2";
142142
EXPECT_EQ(ImageType::jp2, ImageFactory::getType(imagePath));
143143
EXPECT_NO_THROW(ImageFactory::open(imagePath, false));
144144
}

0 commit comments

Comments
 (0)