Skip to content

Commit 1d9d9df

Browse files
committed
fixup wstring functions to use fs::path
Signed-off-by: Rosen Penev <[email protected]>
1 parent 09f8eb1 commit 1d9d9df

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
@@ -523,7 +523,7 @@ class EXIV2API ImageFactory {
523523
*/
524524
static BasicIo::UniquePtr createIo(const std::string& path, bool useCurl = true);
525525
#ifdef _WIN32
526-
static BasicIo::UniquePtr createIo(const std::wstring& path);
526+
static BasicIo::UniquePtr createIo(const std::wstring& path, bool useCurl = true);
527527
#endif
528528
/*!
529529
@brief Create an Image subclass of the appropriate type by reading
@@ -540,7 +540,7 @@ class EXIV2API ImageFactory {
540540
*/
541541
static Image::UniquePtr open(const std::string& path, bool useCurl = true);
542542
#ifdef _WIN32
543-
static Image::UniquePtr open(const std::wstring& path);
543+
static Image::UniquePtr open(const std::wstring& path, bool useCurl = true);
544544
#endif
545545
/*!
546546
@brief Create an Image subclass of the appropriate type by reading
@@ -615,6 +615,9 @@ class EXIV2API ImageFactory {
615615
@return %Image type or Image::none if the type is not recognized.
616616
*/
617617
static ImageType getType(const std::string& path);
618+
#ifdef _WIN32
619+
static ImageType getType(const std::wstring& path);
620+
#endif
618621
/*!
619622
@brief Returns the image type of the provided data buffer.
620623
@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)