diff --git a/Fb2File/Fb2File.cpp b/Fb2File/Fb2File.cpp index cff09be0ea..87e29ca9e7 100644 --- a/Fb2File/Fb2File.cpp +++ b/Fb2File/Fb2File.cpp @@ -2,6 +2,7 @@ #include "../DesktopEditor/xml/include/xmlutils.h" #include "../DesktopEditor/common/Base64.h" #include "../DesktopEditor/common/File.h" +#include "../DesktopEditor/common/Directory.h" #include #include @@ -367,7 +368,7 @@ bool CFb2File::IsFb2File(const std::wstring& sFile) } // Выставление временной (рабочей) папки -void CFb2File::SetImpDirectory(const std::wstring& sFolder) +void CFb2File::SetTmpDirectory(const std::wstring& sFolder) { m_internal->m_sDstFolder = sFolder; } @@ -398,6 +399,8 @@ int CFb2File::Convert (const std::wstring& sPath, const std::wstring& sDirectory // ПРОПУСКАЕМ body + std::wstring sMediaDirectory = sDirectory + L"/media"; + NSDirectory::CreateDirectory(sMediaDirectory); while(m_internal->m_oLightReader.ReadNextNode()) { // Читает картинки @@ -421,7 +424,7 @@ int CFb2File::Convert (const std::wstring& sPath, const std::wstring& sDirectory // Пишет картинку в файл NSFile::CFileBinary oImageWriter; - if (!oImageWriter.CreateFileW(sDirectory + sId)) + if (!oImageWriter.CreateFileW(sMediaDirectory + L"/" + sId)) return false; std::string sBase64 = m_internal->contentA(sId); int nSrcLen = (int)sBase64.length(); diff --git a/Fb2File/Fb2File.h b/Fb2File/Fb2File.h index dbfe9421bc..4b8bbf3e1a 100644 --- a/Fb2File/Fb2File.h +++ b/Fb2File/Fb2File.h @@ -20,7 +20,7 @@ public: ~CFb2File(); bool IsFb2File(const std::wstring& sFile); - void SetImpDirectory(const std::wstring& sFolder); + void SetTmpDirectory(const std::wstring& sFolder); int Convert(const std::wstring& sPath, const std::wstring& sDirectory); }; diff --git a/Fb2File/tests/test_TheLastWish.fb2 b/Fb2File/examples/test1.fb2 similarity index 100% rename from Fb2File/tests/test_TheLastWish.fb2 rename to Fb2File/examples/test1.fb2 diff --git a/Fb2File/test/main.cpp b/Fb2File/test/main.cpp new file mode 100644 index 0000000000..44bb014211 --- /dev/null +++ b/Fb2File/test/main.cpp @@ -0,0 +1,29 @@ +#include + +#include "../Fb2File.h" +#include "../../DesktopEditor/common/File.h" +#include "../../DesktopEditor/common/Directory.h" + +int main() +{ + CFb2File oFile; + oFile.SetTmpDirectory(NSFile::GetProcessDirectory() + L"/tmp"); + + // файл, который открываем + std::wstring sFile = NSFile::GetProcessDirectory() + L"/../../../examples/test1.fb2"; + + // директория, где будем создавать docx + std::wstring sOutputDirectory = NSFile::GetProcessDirectory() + L"/output"; + if (!NSDirectory::Exists(sOutputDirectory)) + NSDirectory::CreateDirectory(sOutputDirectory); + + bool bCheck = oFile.IsFb2File(sFile); + if (!bCheck) + { + std::cout << "This isn't a fb2 file" << std::endl; + return 1; + } + + int nResConvert = oFile.Convert(sFile, sOutputDirectory); + return 0; +} diff --git a/Fb2File/tests/Test_Fb2File/Test_Fb2File.pro b/Fb2File/test/test.pro similarity index 63% rename from Fb2File/tests/Test_Fb2File/Test_Fb2File.pro rename to Fb2File/test/test.pro index 6f2151d76d..bb6e9c3f19 100644 --- a/Fb2File/tests/Test_Fb2File/Test_Fb2File.pro +++ b/Fb2File/test/test.pro @@ -10,8 +10,10 @@ DEFINES += FB2FILE_USE_DYNAMIC_LIBRARY SOURCES += main.cpp -CORE_ROOT_DIR = $$PWD/../../../../core +CORE_ROOT_DIR = $$PWD/../../../core PWD_ROOT_DIR = $$PWD include($$CORE_ROOT_DIR/Common/base.pri) -LIBS += -L$$CORE_BUILDS_LIBRARIES_PATH -lkernel -lFb2File +ADD_DEPENDENCY(kernel, Fb2File) + +DESTDIR = $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX diff --git a/Fb2File/tests/Test_Fb2File/main.cpp b/Fb2File/tests/Test_Fb2File/main.cpp deleted file mode 100644 index fd92fa33d7..0000000000 --- a/Fb2File/tests/Test_Fb2File/main.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include - -#include "../../Fb2File.h" - -int main() -{ - CFb2File oFile; - oFile.SetImpDirectory(L"../../../media/"); - bool bCheck = oFile.IsFb2File(L"../../../../test_TheLastWish.fb2"); - if (!bCheck) - { - std::cout << "This isn't a fb2 file" << std::endl; - return 1; - } - - int nResConvert = oFile.Convert(L"path", L"../../../media/"); - return 0; -} diff --git a/Fb2File/tests/Test_Fb2File/media/cover.jpg b/Fb2File/tests/Test_Fb2File/media/cover.jpg deleted file mode 100644 index 3d805f0fa6..0000000000 Binary files a/Fb2File/tests/Test_Fb2File/media/cover.jpg and /dev/null differ diff --git a/Fb2File/tests/Test_TryToRead_DOM/main.cpp b/Fb2File/tests/Test_TryToRead_DOM/main.cpp deleted file mode 100644 index 8dc663ee9f..0000000000 --- a/Fb2File/tests/Test_TryToRead_DOM/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include "../../../DesktopEditor/xml/include/xmlutils.h" - -int main() -{ - XmlUtils::CXmlNode oNode; - oNode.FromXmlFile(L"../../../../test.xml"); - - return 0; -} diff --git a/Fb2File/xml/dom/main.cpp b/Fb2File/xml/dom/main.cpp new file mode 100644 index 0000000000..83dfe31f2b --- /dev/null +++ b/Fb2File/xml/dom/main.cpp @@ -0,0 +1,10 @@ +#include "../../../DesktopEditor/xml/include/xmlutils.h" +#include "../../../DesktopEditor/common/File.h" + +int main() +{ + XmlUtils::CXmlNode oNode; + oNode.FromXmlFile(NSFile::GetProcessDirectory() + L"/../../../examples/test.xml"); + + return 0; +} diff --git a/Fb2File/tests/TestFunctionsLiteReader/TestFunctionsLiteReader.pro b/Fb2File/xml/dom/test_DOM.pro similarity index 81% rename from Fb2File/tests/TestFunctionsLiteReader/TestFunctionsLiteReader.pro rename to Fb2File/xml/dom/test_DOM.pro index 6dc72246ce..075cc5d53d 100644 --- a/Fb2File/tests/TestFunctionsLiteReader/TestFunctionsLiteReader.pro +++ b/Fb2File/xml/dom/test_DOM.pro @@ -13,3 +13,5 @@ PWD_ROOT_DIR = $$PWD include($$CORE_ROOT_DIR/Common/base.pri) ADD_DEPENDENCY(kernel) + +DESTDIR = $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX diff --git a/Fb2File/tests/test.xml b/Fb2File/xml/examples/test.xml similarity index 100% rename from Fb2File/tests/test.xml rename to Fb2File/xml/examples/test.xml diff --git a/Fb2File/tests/Test_TryToRead_LiteReader/main.cpp b/Fb2File/xml/sax/main.cpp similarity index 89% rename from Fb2File/tests/Test_TryToRead_LiteReader/main.cpp rename to Fb2File/xml/sax/main.cpp index 35ae20e29b..955f628d30 100644 --- a/Fb2File/tests/Test_TryToRead_LiteReader/main.cpp +++ b/Fb2File/xml/sax/main.cpp @@ -1,10 +1,11 @@ #include #include "../../../DesktopEditor/xml/include/xmlutils.h" +#include "../../../DesktopEditor/common/File.h" int main() { XmlUtils::CXmlLiteReader oLightReader; - if (oLightReader.FromFile(L"../../../../test.xml")) + if (oLightReader.FromFile(NSFile::GetProcessDirectory() + L"/../../../examples/test.xml")) { while(oLightReader.ReadNextNode()) { diff --git a/Fb2File/tests/Test_TryToRead_DOM/Test_TryToRead_DOM.pro b/Fb2File/xml/sax/test_SAX.pro similarity index 81% rename from Fb2File/tests/Test_TryToRead_DOM/Test_TryToRead_DOM.pro rename to Fb2File/xml/sax/test_SAX.pro index 6dc72246ce..075cc5d53d 100644 --- a/Fb2File/tests/Test_TryToRead_DOM/Test_TryToRead_DOM.pro +++ b/Fb2File/xml/sax/test_SAX.pro @@ -13,3 +13,5 @@ PWD_ROOT_DIR = $$PWD include($$CORE_ROOT_DIR/Common/base.pri) ADD_DEPENDENCY(kernel) + +DESTDIR = $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX diff --git a/Fb2File/tests/TestFunctionsLiteReader/main.cpp b/Fb2File/xml/tmp/main.cpp similarity index 95% rename from Fb2File/tests/TestFunctionsLiteReader/main.cpp rename to Fb2File/xml/tmp/main.cpp index c8d56addd6..8c88bab552 100644 --- a/Fb2File/tests/TestFunctionsLiteReader/main.cpp +++ b/Fb2File/xml/tmp/main.cpp @@ -1,72 +1,73 @@ -#include -#include "../../../DesktopEditor/xml/include/xmlutils.h" - -int main() -{ - // sax reader - XmlUtils::CXmlLiteReader oLightReader; - /* - Выводы: - Возвращает успешность открытия файла - Читает файл в поток m_pStream - Длина потока в m_lStreamLen - Формирует reader - После чтения файл закрывается - Мысли: - xmlreader.h - функции работы с xml - */ - bool res1 = oLightReader.FromFile(L"../../../../test.xml"); - std::wcout << res1 << std::endl; // true - - /* - Возвращает порядковый номер узла (кажется нет) - Мысли: - Возвращает XmlNodeType_None(0) - */ - XmlUtils::XmlNodeType res2 = oLightReader.GetNodeType(); - std::wcout << res2<< " " << oLightReader.GetName() << std::endl; // 0 пусто, т.к. текущий узел отсутствует - - /* - GetName() - возвращает имя текущего узла - GetDepth() - возвращает глубину текущего узла - */ - - /* - Возвращает успешность чтения узла указанного типа - По ссылке сохраняет тип узла - Мысли: - Значение XmlNodeType_None(0) преобразуется в XmlNodeType_Element(1) - */ - bool res3 = oLightReader.Read(res2); // Прочитает company - std::wcout << res3 << " " << res2 << " " << oLightReader.GetName() << std::endl; // true 1 - - /* - Мысли: - Возвращает успешность чтения следующего узла - В reader изменяются глубина depth если узел вложенный - И текущий узел node - */ - bool res4 = oLightReader.ReadNextNode(); // Прочитает staff - std::wcout << res4 << " " << oLightReader.GetName() << std::endl; // true - bool res5 = oLightReader.ReadNextNode(); // Прочитает firstname - std::wcout << res5 << " " << oLightReader.GetName() << std::endl; // true - - /* - Возвращает успешность чтения следующего узла на той же глубине - 1 - Внешний тэг не в счет - */ - bool res6 = oLightReader.ReadNextSiblingNode(1); // Прочитает lastname - std::wcout << res6 << " " << oLightReader.GetName() << std::endl; // true - //bool res7 = oLightReader.ReadNextSiblingNode(1); // Прочитает staff закрывающий - //std::wcout << res7 << std::endl; // false, т.к. прочитанный узел на другой глубине - - /* - Мысли: - Принудительно читает узел на той-же глубине, - Если узла нет, то создает узел text - */ - bool res7 = oLightReader.ReadNextSiblingNode2(1); // Прочитает text (ЧТО ЭТО) родитель parent будет staff - std::wcout << res7 << " " << oLightReader.GetName() << std::endl; // true - - return 0; -} +#include +#include "../../../DesktopEditor/xml/include/xmlutils.h" +#include "../../../DesktopEditor/common/File.h" + +int main() +{ + // sax reader + XmlUtils::CXmlLiteReader oLightReader; + /* + Выводы: + Возвращает успешность открытия файла + Читает файл в поток m_pStream + Длина потока в m_lStreamLen + Формирует reader + После чтения файл закрывается + Мысли: + xmlreader.h - функции работы с xml + */ + bool res1 = oLightReader.FromFile(NSFile::GetProcessDirectory() + L"/../../../examples/test.xml"); + std::wcout << res1 << std::endl; // true + + /* + Возвращает порядковый номер узла (кажется нет) + Мысли: + Возвращает XmlNodeType_None(0) + */ + XmlUtils::XmlNodeType res2 = oLightReader.GetNodeType(); + std::wcout << res2<< " " << oLightReader.GetName() << std::endl; // 0 пусто, т.к. текущий узел отсутствует + + /* + GetName() - возвращает имя текущего узла + GetDepth() - возвращает глубину текущего узла + */ + + /* + Возвращает успешность чтения узла указанного типа + По ссылке сохраняет тип узла + Мысли: + Значение XmlNodeType_None(0) преобразуется в XmlNodeType_Element(1) + */ + bool res3 = oLightReader.Read(res2); // Прочитает company + std::wcout << res3 << " " << res2 << " " << oLightReader.GetName() << std::endl; // true 1 + + /* + Мысли: + Возвращает успешность чтения следующего узла + В reader изменяются глубина depth если узел вложенный + И текущий узел node + */ + bool res4 = oLightReader.ReadNextNode(); // Прочитает staff + std::wcout << res4 << " " << oLightReader.GetName() << std::endl; // true + bool res5 = oLightReader.ReadNextNode(); // Прочитает firstname + std::wcout << res5 << " " << oLightReader.GetName() << std::endl; // true + + /* + Возвращает успешность чтения следующего узла на той же глубине - 1 + Внешний тэг не в счет + */ + bool res6 = oLightReader.ReadNextSiblingNode(1); // Прочитает lastname + std::wcout << res6 << " " << oLightReader.GetName() << std::endl; // true + //bool res7 = oLightReader.ReadNextSiblingNode(1); // Прочитает staff закрывающий + //std::wcout << res7 << std::endl; // false, т.к. прочитанный узел на другой глубине + + /* + Мысли: + Принудительно читает узел на той-же глубине, + Если узла нет, то создает узел text + */ + bool res7 = oLightReader.ReadNextSiblingNode2(1); // Прочитает text (ЧТО ЭТО) родитель parent будет staff + std::wcout << res7 << " " << oLightReader.GetName() << std::endl; // true + + return 0; +} diff --git a/Fb2File/tests/Test_TryToRead_LiteReader/Test_TryToRead_LiteReader.pro b/Fb2File/xml/tmp/test.pro similarity index 81% rename from Fb2File/tests/Test_TryToRead_LiteReader/Test_TryToRead_LiteReader.pro rename to Fb2File/xml/tmp/test.pro index 6dc72246ce..075cc5d53d 100644 --- a/Fb2File/tests/Test_TryToRead_LiteReader/Test_TryToRead_LiteReader.pro +++ b/Fb2File/xml/tmp/test.pro @@ -13,3 +13,5 @@ PWD_ROOT_DIR = $$PWD include($$CORE_ROOT_DIR/Common/base.pri) ADD_DEPENDENCY(kernel) + +DESTDIR = $$PWD/build/$$CORE_BUILDS_PLATFORM_PREFIX