| Revision | 2b26b8f68ccb6d34fcf6b3d66a0588a47607b1bc (tree) |
|---|---|
| Time | 2011-04-14 18:39:47 |
| Author | |
| Commiter | Yasuhiro ABE |
Revised the ReadMe.txt file.
Suppressed debug messages when the "Release" configuration.
| @@ -1,7 +1,10 @@ | ||
| 1 | - | |
| 2 | -BuildLog.htm | |
| 3 | -QuickHashChecker.exe | |
| 4 | -QuickHashChecker.ilk | |
| 5 | -QuickHashChecker.pdb | |
| 6 | -QuickHashChecker/Debug/* | |
| 7 | -QuickHashChecker.ncb | |
| \ No newline at end of file | ||
| 1 | + | |
| 2 | +BuildLog.htm | |
| 3 | +QuickHashChecker.exe | |
| 4 | +QuickHashChecker.ilk | |
| 5 | +QuickHashChecker.pdb | |
| 6 | +QuickHashChecker/Debug/* | |
| 7 | +QuickHashChecker/Release/* | |
| 8 | +QuickHashChecker.ncb | |
| 9 | +debug | |
| 10 | +release | |
| \ No newline at end of file |
| @@ -1,7 +1,159 @@ | ||
| 1 | -// QuickHashChecker.cpp : コンソール アプリケーションのエントリ ポイントを定義します。 | |
| 2 | -// | |
| 1 | +/** | |
| 2 | + * Copyright (C) 2010,2011 Yasuhiro ABE <yasu@yasundial.org> | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + **/ | |
| 3 | 16 | |
| 4 | 17 | #include "stdafx.h" |
| 5 | 18 | |
| 19 | +std::string genuuid() { | |
| 20 | + GUID guid; | |
| 21 | + HRESULT hr = CoCreateGuid(&guid); | |
| 22 | + | |
| 23 | + std::ostringstream oss; | |
| 24 | + oss << toHex<int>(guid.Data1,8) << "-" << toHex(guid.Data2,4) << "-" << | |
| 25 | + toHex(guid.Data3,4) << "-" << toHex((int)guid.Data4[0],2) << toHex((int)guid.Data4[1],2) << | |
| 26 | + "-" << std::setw(2) << std::setfill('0') << std::hex << (int)guid.Data4[2] << (int)guid.Data4[3] << | |
| 27 | + (int)guid.Data4[4] << (int)guid.Data4[5] << (int)guid.Data4[6] << (int)guid.Data4[7]; | |
| 28 | + | |
| 29 | + return oss.str(); | |
| 30 | +} | |
| 6 | 31 | |
| 32 | +static void help(TCHAR* cmdpath) { | |
| 33 | + using namespace std; | |
| 34 | + _tprintf(_T("Usage: %s <dbfilepath> <action> <filepath>\n"), cmdpath); | |
| 35 | + _tprintf(_T("\t<action>: generate|check|delete")); | |
| 36 | +} | |
| 37 | + | |
| 38 | +int _tmain(int argc, _TCHAR* argv[]) | |
| 39 | +{ | |
| 40 | + if(argc != 4) { | |
| 41 | + help(argv[0]); | |
| 42 | + return 1; | |
| 43 | + } | |
| 44 | + const tstring dbname(argv[1]); | |
| 45 | + const tstring action(argv[2]); | |
| 46 | + const tstring pathname(argv[3]); | |
| 47 | + boost::filesystem::path p(argv[3]); | |
| 48 | + if(! boost::filesystem::exists(p)) { | |
| 49 | + help(argv[0]); | |
| 50 | + return 1; | |
| 51 | + } | |
| 52 | + boost::filesystem::path dbpath(dbname); | |
| 53 | + | |
| 54 | + TCHAR* dbfilename = argv[1]; | |
| 55 | + TCHAR* filename = argv[3]; | |
| 56 | + | |
| 57 | + yamain* main = new yamain(filename, dbfilename); | |
| 58 | + | |
| 59 | + std::string dbuuid = main->getUUIDFromDB(); | |
| 60 | + std::string diskuuid = main->getUUIDFromDisk(); | |
| 61 | +#ifdef _DEBUG | |
| 62 | + std::cout << "dbuuid: " << dbuuid << std::endl; | |
| 63 | + std::cout << "diskuuid: " << diskuuid << std::endl; | |
| 64 | +#endif | |
| 65 | + | |
| 66 | + int rc; | |
| 67 | + std::string uuid; | |
| 68 | + uuidstatus status = bad; | |
| 69 | + if (dbuuid.empty() && diskuuid.empty()) { | |
| 70 | + // initialize db and disk | |
| 71 | + uuid = genuuid(); | |
| 72 | + rc = main->setUUIDToDB(uuid); | |
| 73 | + if(rc) { | |
| 74 | + rc = main->setUUIDToDisk(uuid); | |
| 75 | + } else { | |
| 76 | + status = bad; | |
| 77 | + } | |
| 78 | + } else if( dbuuid.empty() && ! diskuuid.empty()) { | |
| 79 | + // recheck uuid from db | |
| 80 | + uuid = diskuuid; | |
| 81 | + if(main->checkUUIDonDB(diskuuid)) { | |
| 82 | + // exists on db: file was moved | |
| 83 | + rc = main->updateFilepathonDBByUUID(filename, diskuuid); | |
| 84 | + if(rc) { | |
| 85 | + status = moved; | |
| 86 | + } else { | |
| 87 | + status = bad; | |
| 88 | + } | |
| 89 | + } else { | |
| 90 | + // maybe, something wrong | |
| 91 | + rc = main->setUUIDToDB(diskuuid); | |
| 92 | + if(rc) { | |
| 93 | + // recreated | |
| 94 | + status = not_found_on_db; | |
| 95 | + } else { | |
| 96 | + // maybe, a db file was initialized. | |
| 97 | + status = bad; | |
| 98 | + } | |
| 99 | + } | |
| 100 | + } else if(! dbuuid.empty() && diskuuid.empty()) { | |
| 101 | + // file was recreated | |
| 102 | + rc = main->setUUIDToDisk(dbuuid); | |
| 103 | + if(rc) { | |
| 104 | + uuid = dbuuid; | |
| 105 | + status = recreated; | |
| 106 | + } else { | |
| 107 | + status = bad; | |
| 108 | + } | |
| 109 | + } else if(! dbuuid.empty() && ! diskuuid.empty()) { | |
| 110 | + // normal state. just update check. | |
| 111 | + if(dbuuid.compare(diskuuid) == 0) { | |
| 112 | + | |
| 113 | + uuid = diskuuid; | |
| 114 | + status = normal; | |
| 115 | + } else { | |
| 116 | + main->setUUIDToDB(diskuuid); | |
| 117 | + uuid = diskuuid; | |
| 118 | + status = moved; | |
| 119 | + } | |
| 120 | + } | |
| 121 | + switch(status) { | |
| 122 | + case normal: | |
| 123 | +#ifdef _DEBUG | |
| 124 | + std::cout << "[status] normal." << std::endl; | |
| 125 | +#endif | |
| 126 | + break; | |
| 127 | + case recreated: | |
| 128 | + std::cout << "[status] file was recreated." << std::endl; | |
| 129 | + break; | |
| 130 | + case moved: | |
| 131 | + std::cout << "[status] file was moved." << std::endl; | |
| 132 | + break; | |
| 133 | + case not_found_on_db: | |
| 134 | + std::cout << "[status] data mismatched (, local db might be initialized.)" << std::endl; | |
| 135 | + break; | |
| 136 | + case bad: | |
| 137 | + std::cout << "[status] error" << std::endl; | |
| 138 | + break; | |
| 139 | + } | |
| 140 | +#ifdef _DEBUG | |
| 141 | + std::cout << std::endl << "fileid: " << uuid << std::endl; | |
| 142 | +#else | |
| 143 | + std::cout << std::endl; | |
| 144 | +#endif | |
| 145 | + if(action.compare(_T("check")) == 0) { | |
| 146 | + rc = main->checkHash(true); | |
| 147 | + } else if(action.compare(_T("generate")) == 0) { | |
| 148 | + rc = main->createHash(); | |
| 149 | + } else if(action.compare(_T("delete")) == 0) { | |
| 150 | + rc = main->deleteData(); | |
| 151 | + } | |
| 152 | +#ifdef _DEBUG | |
| 153 | + _tprintf(_T("action: %s\n"), action.c_str()); | |
| 154 | +#endif | |
| 155 | + | |
| 156 | + delete main; | |
| 157 | + return 0; | |
| 158 | +} | |
| 7 | 159 |
| @@ -1,275 +1,277 @@ | ||
| 1 | -<?xml version="1.0" encoding="shift_jis"?> | |
| 2 | -<VisualStudioProject | |
| 3 | - ProjectType="Visual C++" | |
| 4 | - Version="8.00" | |
| 5 | - Name="QuickHashChecker" | |
| 6 | - ProjectGUID="{306D788E-4714-486E-B509-415B16EB7BEB}" | |
| 7 | - RootNamespace="QuickHashChecker" | |
| 8 | - Keyword="Win32Proj" | |
| 9 | - > | |
| 10 | - <Platforms> | |
| 11 | - <Platform | |
| 12 | - Name="Win32" | |
| 13 | - /> | |
| 14 | - </Platforms> | |
| 15 | - <ToolFiles> | |
| 16 | - </ToolFiles> | |
| 17 | - <Configurations> | |
| 18 | - <Configuration | |
| 19 | - Name="Debug|Win32" | |
| 20 | - OutputDirectory="$(SolutionDir)$(ConfigurationName)" | |
| 21 | - IntermediateDirectory="$(ConfigurationName)" | |
| 22 | - ConfigurationType="1" | |
| 23 | - CharacterSet="1" | |
| 24 | - > | |
| 25 | - <Tool | |
| 26 | - Name="VCPreBuildEventTool" | |
| 27 | - /> | |
| 28 | - <Tool | |
| 29 | - Name="VCCustomBuildTool" | |
| 30 | - /> | |
| 31 | - <Tool | |
| 32 | - Name="VCXMLDataGeneratorTool" | |
| 33 | - /> | |
| 34 | - <Tool | |
| 35 | - Name="VCWebServiceProxyGeneratorTool" | |
| 36 | - /> | |
| 37 | - <Tool | |
| 38 | - Name="VCMIDLTool" | |
| 39 | - /> | |
| 40 | - <Tool | |
| 41 | - Name="VCCLCompilerTool" | |
| 42 | - Optimization="0" | |
| 43 | - AdditionalIncludeDirectories="C:\usr\local\sqlite3070500;"C:\Program Files\boost\boost_1_46_1";"C:\Users\yasu\Documents\Visual Studio 2005\Projects\cryptopp561"" | |
| 44 | - PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" | |
| 45 | - MinimalRebuild="true" | |
| 46 | - BasicRuntimeChecks="3" | |
| 47 | - RuntimeLibrary="3" | |
| 48 | - UsePrecompiledHeader="2" | |
| 49 | - WarningLevel="3" | |
| 50 | - Detect64BitPortabilityProblems="true" | |
| 51 | - DebugInformationFormat="4" | |
| 52 | - /> | |
| 53 | - <Tool | |
| 54 | - Name="VCManagedResourceCompilerTool" | |
| 55 | - /> | |
| 56 | - <Tool | |
| 57 | - Name="VCResourceCompilerTool" | |
| 58 | - /> | |
| 59 | - <Tool | |
| 60 | - Name="VCPreLinkEventTool" | |
| 61 | - /> | |
| 62 | - <Tool | |
| 63 | - Name="VCLinkerTool" | |
| 64 | - LinkIncremental="2" | |
| 65 | - AdditionalLibraryDirectories="C:\usr\local\sqlite3070500;"C:\Program Files\boost\boost_1_46_1\lib";"C:\Users\yasu\Documents\Visual Studio 2005\Projects\cryptopp561\Win32\dll_output\debug"" | |
| 66 | - GenerateDebugInformation="true" | |
| 67 | - SubSystem="1" | |
| 68 | - TargetMachine="1" | |
| 69 | - /> | |
| 70 | - <Tool | |
| 71 | - Name="VCALinkTool" | |
| 72 | - /> | |
| 73 | - <Tool | |
| 74 | - Name="VCManifestTool" | |
| 75 | - /> | |
| 76 | - <Tool | |
| 77 | - Name="VCXDCMakeTool" | |
| 78 | - /> | |
| 79 | - <Tool | |
| 80 | - Name="VCBscMakeTool" | |
| 81 | - /> | |
| 82 | - <Tool | |
| 83 | - Name="VCFxCopTool" | |
| 84 | - /> | |
| 85 | - <Tool | |
| 86 | - Name="VCAppVerifierTool" | |
| 87 | - /> | |
| 88 | - <Tool | |
| 89 | - Name="VCWebDeploymentTool" | |
| 90 | - /> | |
| 91 | - <Tool | |
| 92 | - Name="VCPostBuildEventTool" | |
| 93 | - /> | |
| 94 | - </Configuration> | |
| 95 | - <Configuration | |
| 96 | - Name="Release|Win32" | |
| 97 | - OutputDirectory="$(SolutionDir)$(ConfigurationName)" | |
| 98 | - IntermediateDirectory="$(ConfigurationName)" | |
| 99 | - ConfigurationType="1" | |
| 100 | - CharacterSet="1" | |
| 101 | - WholeProgramOptimization="1" | |
| 102 | - > | |
| 103 | - <Tool | |
| 104 | - Name="VCPreBuildEventTool" | |
| 105 | - /> | |
| 106 | - <Tool | |
| 107 | - Name="VCCustomBuildTool" | |
| 108 | - /> | |
| 109 | - <Tool | |
| 110 | - Name="VCXMLDataGeneratorTool" | |
| 111 | - /> | |
| 112 | - <Tool | |
| 113 | - Name="VCWebServiceProxyGeneratorTool" | |
| 114 | - /> | |
| 115 | - <Tool | |
| 116 | - Name="VCMIDLTool" | |
| 117 | - /> | |
| 118 | - <Tool | |
| 119 | - Name="VCCLCompilerTool" | |
| 120 | - PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" | |
| 121 | - RuntimeLibrary="2" | |
| 122 | - UsePrecompiledHeader="2" | |
| 123 | - WarningLevel="3" | |
| 124 | - Detect64BitPortabilityProblems="true" | |
| 125 | - DebugInformationFormat="3" | |
| 126 | - /> | |
| 127 | - <Tool | |
| 128 | - Name="VCManagedResourceCompilerTool" | |
| 129 | - /> | |
| 130 | - <Tool | |
| 131 | - Name="VCResourceCompilerTool" | |
| 132 | - /> | |
| 133 | - <Tool | |
| 134 | - Name="VCPreLinkEventTool" | |
| 135 | - /> | |
| 136 | - <Tool | |
| 137 | - Name="VCLinkerTool" | |
| 138 | - LinkIncremental="1" | |
| 139 | - GenerateDebugInformation="true" | |
| 140 | - SubSystem="1" | |
| 141 | - OptimizeReferences="2" | |
| 142 | - EnableCOMDATFolding="2" | |
| 143 | - TargetMachine="1" | |
| 144 | - /> | |
| 145 | - <Tool | |
| 146 | - Name="VCALinkTool" | |
| 147 | - /> | |
| 148 | - <Tool | |
| 149 | - Name="VCManifestTool" | |
| 150 | - /> | |
| 151 | - <Tool | |
| 152 | - Name="VCXDCMakeTool" | |
| 153 | - /> | |
| 154 | - <Tool | |
| 155 | - Name="VCBscMakeTool" | |
| 156 | - /> | |
| 157 | - <Tool | |
| 158 | - Name="VCFxCopTool" | |
| 159 | - /> | |
| 160 | - <Tool | |
| 161 | - Name="VCAppVerifierTool" | |
| 162 | - /> | |
| 163 | - <Tool | |
| 164 | - Name="VCWebDeploymentTool" | |
| 165 | - /> | |
| 166 | - <Tool | |
| 167 | - Name="VCPostBuildEventTool" | |
| 168 | - /> | |
| 169 | - </Configuration> | |
| 170 | - </Configurations> | |
| 171 | - <References> | |
| 172 | - </References> | |
| 173 | - <Files> | |
| 174 | - <Filter | |
| 175 | - Name="ソース ファイル" | |
| 176 | - Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" | |
| 177 | - UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" | |
| 178 | - > | |
| 179 | - <File | |
| 180 | - RelativePath=".\QuickHashChecker.cpp" | |
| 181 | - > | |
| 182 | - </File> | |
| 183 | - <File | |
| 184 | - RelativePath=".\sqlite3pp.cpp" | |
| 185 | - > | |
| 186 | - </File> | |
| 187 | - <File | |
| 188 | - RelativePath=".\stdafx.cpp" | |
| 189 | - > | |
| 190 | - <FileConfiguration | |
| 191 | - Name="Debug|Win32" | |
| 192 | - > | |
| 193 | - <Tool | |
| 194 | - Name="VCCLCompilerTool" | |
| 195 | - UsePrecompiledHeader="1" | |
| 196 | - /> | |
| 197 | - </FileConfiguration> | |
| 198 | - <FileConfiguration | |
| 199 | - Name="Release|Win32" | |
| 200 | - > | |
| 201 | - <Tool | |
| 202 | - Name="VCCLCompilerTool" | |
| 203 | - UsePrecompiledHeader="1" | |
| 204 | - /> | |
| 205 | - </FileConfiguration> | |
| 206 | - </File> | |
| 207 | - <File | |
| 208 | - RelativePath=".\yahash.cpp" | |
| 209 | - > | |
| 210 | - </File> | |
| 211 | - <File | |
| 212 | - RelativePath=".\yamain.cpp" | |
| 213 | - > | |
| 214 | - </File> | |
| 215 | - <File | |
| 216 | - RelativePath=".\yantfsstream.cpp" | |
| 217 | - > | |
| 218 | - </File> | |
| 219 | - <File | |
| 220 | - RelativePath=".\yaprops.cpp" | |
| 221 | - > | |
| 222 | - </File> | |
| 223 | - <File | |
| 224 | - RelativePath=".\yasqlite3db.cpp" | |
| 225 | - > | |
| 226 | - </File> | |
| 227 | - </Filter> | |
| 228 | - <Filter | |
| 229 | - Name="ヘッダー ファイル" | |
| 230 | - Filter="h;hpp;hxx;hm;inl;inc;xsd" | |
| 231 | - UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" | |
| 232 | - > | |
| 233 | - <File | |
| 234 | - RelativePath=".\sqlite3pp.h" | |
| 235 | - > | |
| 236 | - </File> | |
| 237 | - <File | |
| 238 | - RelativePath=".\stdafx.h" | |
| 239 | - > | |
| 240 | - </File> | |
| 241 | - <File | |
| 242 | - RelativePath=".\yahash.h" | |
| 243 | - > | |
| 244 | - </File> | |
| 245 | - <File | |
| 246 | - RelativePath=".\yamain.h" | |
| 247 | - > | |
| 248 | - </File> | |
| 249 | - <File | |
| 250 | - RelativePath=".\yantfsstream.h" | |
| 251 | - > | |
| 252 | - </File> | |
| 253 | - <File | |
| 254 | - RelativePath=".\yaprops.h" | |
| 255 | - > | |
| 256 | - </File> | |
| 257 | - <File | |
| 258 | - RelativePath=".\yasqlite3db.h" | |
| 259 | - > | |
| 260 | - </File> | |
| 261 | - </Filter> | |
| 262 | - <Filter | |
| 263 | - Name="リソース ファイル" | |
| 264 | - Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" | |
| 265 | - UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" | |
| 266 | - > | |
| 267 | - </Filter> | |
| 268 | - <File | |
| 269 | - RelativePath=".\ReadMe.txt" | |
| 270 | - > | |
| 271 | - </File> | |
| 272 | - </Files> | |
| 273 | - <Globals> | |
| 274 | - </Globals> | |
| 275 | -</VisualStudioProject> | |
| 1 | +<?xml version="1.0" encoding="shift_jis"?> | |
| 2 | +<VisualStudioProject | |
| 3 | + ProjectType="Visual C++" | |
| 4 | + Version="8.00" | |
| 5 | + Name="QuickHashChecker" | |
| 6 | + ProjectGUID="{306D788E-4714-486E-B509-415B16EB7BEB}" | |
| 7 | + RootNamespace="QuickHashChecker" | |
| 8 | + Keyword="Win32Proj" | |
| 9 | + > | |
| 10 | + <Platforms> | |
| 11 | + <Platform | |
| 12 | + Name="Win32" | |
| 13 | + /> | |
| 14 | + </Platforms> | |
| 15 | + <ToolFiles> | |
| 16 | + </ToolFiles> | |
| 17 | + <Configurations> | |
| 18 | + <Configuration | |
| 19 | + Name="Debug|Win32" | |
| 20 | + OutputDirectory="$(SolutionDir)$(ConfigurationName)" | |
| 21 | + IntermediateDirectory="$(ConfigurationName)" | |
| 22 | + ConfigurationType="1" | |
| 23 | + CharacterSet="1" | |
| 24 | + > | |
| 25 | + <Tool | |
| 26 | + Name="VCPreBuildEventTool" | |
| 27 | + /> | |
| 28 | + <Tool | |
| 29 | + Name="VCCustomBuildTool" | |
| 30 | + /> | |
| 31 | + <Tool | |
| 32 | + Name="VCXMLDataGeneratorTool" | |
| 33 | + /> | |
| 34 | + <Tool | |
| 35 | + Name="VCWebServiceProxyGeneratorTool" | |
| 36 | + /> | |
| 37 | + <Tool | |
| 38 | + Name="VCMIDLTool" | |
| 39 | + /> | |
| 40 | + <Tool | |
| 41 | + Name="VCCLCompilerTool" | |
| 42 | + Optimization="0" | |
| 43 | + AdditionalIncludeDirectories="C:\usr\local\sqlite3070500;"C:\Program Files\boost\boost_1_46_1";"C:\Users\yasu\Documents\Visual Studio 2005\Projects\cryptopp561"" | |
| 44 | + PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE" | |
| 45 | + MinimalRebuild="true" | |
| 46 | + BasicRuntimeChecks="3" | |
| 47 | + RuntimeLibrary="3" | |
| 48 | + UsePrecompiledHeader="2" | |
| 49 | + WarningLevel="3" | |
| 50 | + Detect64BitPortabilityProblems="true" | |
| 51 | + DebugInformationFormat="4" | |
| 52 | + /> | |
| 53 | + <Tool | |
| 54 | + Name="VCManagedResourceCompilerTool" | |
| 55 | + /> | |
| 56 | + <Tool | |
| 57 | + Name="VCResourceCompilerTool" | |
| 58 | + /> | |
| 59 | + <Tool | |
| 60 | + Name="VCPreLinkEventTool" | |
| 61 | + /> | |
| 62 | + <Tool | |
| 63 | + Name="VCLinkerTool" | |
| 64 | + LinkIncremental="2" | |
| 65 | + AdditionalLibraryDirectories="C:\usr\local\sqlite3070500;"C:\Program Files\boost\boost_1_46_1\lib";"C:\Users\yasu\Documents\Visual Studio 2005\Projects\cryptopp561\Win32\dll_output\debug"" | |
| 66 | + GenerateDebugInformation="true" | |
| 67 | + SubSystem="1" | |
| 68 | + TargetMachine="1" | |
| 69 | + /> | |
| 70 | + <Tool | |
| 71 | + Name="VCALinkTool" | |
| 72 | + /> | |
| 73 | + <Tool | |
| 74 | + Name="VCManifestTool" | |
| 75 | + /> | |
| 76 | + <Tool | |
| 77 | + Name="VCXDCMakeTool" | |
| 78 | + /> | |
| 79 | + <Tool | |
| 80 | + Name="VCBscMakeTool" | |
| 81 | + /> | |
| 82 | + <Tool | |
| 83 | + Name="VCFxCopTool" | |
| 84 | + /> | |
| 85 | + <Tool | |
| 86 | + Name="VCAppVerifierTool" | |
| 87 | + /> | |
| 88 | + <Tool | |
| 89 | + Name="VCWebDeploymentTool" | |
| 90 | + /> | |
| 91 | + <Tool | |
| 92 | + Name="VCPostBuildEventTool" | |
| 93 | + /> | |
| 94 | + </Configuration> | |
| 95 | + <Configuration | |
| 96 | + Name="Release|Win32" | |
| 97 | + OutputDirectory="$(SolutionDir)$(ConfigurationName)" | |
| 98 | + IntermediateDirectory="$(ConfigurationName)" | |
| 99 | + ConfigurationType="1" | |
| 100 | + CharacterSet="1" | |
| 101 | + WholeProgramOptimization="1" | |
| 102 | + > | |
| 103 | + <Tool | |
| 104 | + Name="VCPreBuildEventTool" | |
| 105 | + /> | |
| 106 | + <Tool | |
| 107 | + Name="VCCustomBuildTool" | |
| 108 | + /> | |
| 109 | + <Tool | |
| 110 | + Name="VCXMLDataGeneratorTool" | |
| 111 | + /> | |
| 112 | + <Tool | |
| 113 | + Name="VCWebServiceProxyGeneratorTool" | |
| 114 | + /> | |
| 115 | + <Tool | |
| 116 | + Name="VCMIDLTool" | |
| 117 | + /> | |
| 118 | + <Tool | |
| 119 | + Name="VCCLCompilerTool" | |
| 120 | + AdditionalIncludeDirectories="C:\usr\local\sqlite3070600;"C:\Program Files\boost\boost_1_46_1";"C:\Users\yasu\Documents\Visual Studio 2005\Projects\cryptopp561"" | |
| 121 | + PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE" | |
| 122 | + RuntimeLibrary="2" | |
| 123 | + UsePrecompiledHeader="2" | |
| 124 | + WarningLevel="3" | |
| 125 | + Detect64BitPortabilityProblems="true" | |
| 126 | + DebugInformationFormat="3" | |
| 127 | + /> | |
| 128 | + <Tool | |
| 129 | + Name="VCManagedResourceCompilerTool" | |
| 130 | + /> | |
| 131 | + <Tool | |
| 132 | + Name="VCResourceCompilerTool" | |
| 133 | + /> | |
| 134 | + <Tool | |
| 135 | + Name="VCPreLinkEventTool" | |
| 136 | + /> | |
| 137 | + <Tool | |
| 138 | + Name="VCLinkerTool" | |
| 139 | + LinkIncremental="1" | |
| 140 | + AdditionalLibraryDirectories="C:\usr\local\sqlite3070600;"C:\Program Files\boost\boost_1_46_1\lib";"C:\Users\yasu\Documents\Visual Studio 2005\Projects\cryptopp561\Win32\dll_output\release"" | |
| 141 | + GenerateDebugInformation="true" | |
| 142 | + SubSystem="1" | |
| 143 | + OptimizeReferences="2" | |
| 144 | + EnableCOMDATFolding="2" | |
| 145 | + TargetMachine="1" | |
| 146 | + /> | |
| 147 | + <Tool | |
| 148 | + Name="VCALinkTool" | |
| 149 | + /> | |
| 150 | + <Tool | |
| 151 | + Name="VCManifestTool" | |
| 152 | + /> | |
| 153 | + <Tool | |
| 154 | + Name="VCXDCMakeTool" | |
| 155 | + /> | |
| 156 | + <Tool | |
| 157 | + Name="VCBscMakeTool" | |
| 158 | + /> | |
| 159 | + <Tool | |
| 160 | + Name="VCFxCopTool" | |
| 161 | + /> | |
| 162 | + <Tool | |
| 163 | + Name="VCAppVerifierTool" | |
| 164 | + /> | |
| 165 | + <Tool | |
| 166 | + Name="VCWebDeploymentTool" | |
| 167 | + /> | |
| 168 | + <Tool | |
| 169 | + Name="VCPostBuildEventTool" | |
| 170 | + /> | |
| 171 | + </Configuration> | |
| 172 | + </Configurations> | |
| 173 | + <References> | |
| 174 | + </References> | |
| 175 | + <Files> | |
| 176 | + <Filter | |
| 177 | + Name="ソース ファイル" | |
| 178 | + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" | |
| 179 | + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" | |
| 180 | + > | |
| 181 | + <File | |
| 182 | + RelativePath=".\QuickHashChecker.cpp" | |
| 183 | + > | |
| 184 | + </File> | |
| 185 | + <File | |
| 186 | + RelativePath=".\sqlite3pp.cpp" | |
| 187 | + > | |
| 188 | + </File> | |
| 189 | + <File | |
| 190 | + RelativePath=".\stdafx.cpp" | |
| 191 | + > | |
| 192 | + <FileConfiguration | |
| 193 | + Name="Debug|Win32" | |
| 194 | + > | |
| 195 | + <Tool | |
| 196 | + Name="VCCLCompilerTool" | |
| 197 | + UsePrecompiledHeader="1" | |
| 198 | + /> | |
| 199 | + </FileConfiguration> | |
| 200 | + <FileConfiguration | |
| 201 | + Name="Release|Win32" | |
| 202 | + > | |
| 203 | + <Tool | |
| 204 | + Name="VCCLCompilerTool" | |
| 205 | + UsePrecompiledHeader="1" | |
| 206 | + /> | |
| 207 | + </FileConfiguration> | |
| 208 | + </File> | |
| 209 | + <File | |
| 210 | + RelativePath=".\yahash.cpp" | |
| 211 | + > | |
| 212 | + </File> | |
| 213 | + <File | |
| 214 | + RelativePath=".\yamain.cpp" | |
| 215 | + > | |
| 216 | + </File> | |
| 217 | + <File | |
| 218 | + RelativePath=".\yantfsstream.cpp" | |
| 219 | + > | |
| 220 | + </File> | |
| 221 | + <File | |
| 222 | + RelativePath=".\yaprops.cpp" | |
| 223 | + > | |
| 224 | + </File> | |
| 225 | + <File | |
| 226 | + RelativePath=".\yasqlite3db.cpp" | |
| 227 | + > | |
| 228 | + </File> | |
| 229 | + </Filter> | |
| 230 | + <Filter | |
| 231 | + Name="ヘッダー ファイル" | |
| 232 | + Filter="h;hpp;hxx;hm;inl;inc;xsd" | |
| 233 | + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" | |
| 234 | + > | |
| 235 | + <File | |
| 236 | + RelativePath=".\sqlite3pp.h" | |
| 237 | + > | |
| 238 | + </File> | |
| 239 | + <File | |
| 240 | + RelativePath=".\stdafx.h" | |
| 241 | + > | |
| 242 | + </File> | |
| 243 | + <File | |
| 244 | + RelativePath=".\yahash.h" | |
| 245 | + > | |
| 246 | + </File> | |
| 247 | + <File | |
| 248 | + RelativePath=".\yamain.h" | |
| 249 | + > | |
| 250 | + </File> | |
| 251 | + <File | |
| 252 | + RelativePath=".\yantfsstream.h" | |
| 253 | + > | |
| 254 | + </File> | |
| 255 | + <File | |
| 256 | + RelativePath=".\yaprops.h" | |
| 257 | + > | |
| 258 | + </File> | |
| 259 | + <File | |
| 260 | + RelativePath=".\yasqlite3db.h" | |
| 261 | + > | |
| 262 | + </File> | |
| 263 | + </Filter> | |
| 264 | + <Filter | |
| 265 | + Name="リソース ファイル" | |
| 266 | + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" | |
| 267 | + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" | |
| 268 | + > | |
| 269 | + </Filter> | |
| 270 | + <File | |
| 271 | + RelativePath=".\ReadMe.txt" | |
| 272 | + > | |
| 273 | + </File> | |
| 274 | + </Files> | |
| 275 | + <Globals> | |
| 276 | + </Globals> | |
| 277 | +</VisualStudioProject> |
| @@ -1,39 +1,45 @@ | ||
| 1 | -======================================================================== | |
| 2 | - コンソール アプリケーション : QuickHashChecker プロジェクトの概要 | |
| 3 | -======================================================================== | |
| 4 | - | |
| 5 | -この QuickHashChecker アプリケーションは、AppWizard によって作成されました。 | |
| 6 | - | |
| 7 | -このファイルには、QuickHashChecker アプリケーションを構成する各ファイルの | |
| 8 | -内容の概略が記述されています。 | |
| 9 | - | |
| 10 | - | |
| 11 | -QuickHashChecker.vcproj | |
| 12 | - これは、アプリケーション ウィザードで生成される VC++ プロジェクトのメインの | |
| 13 | - プロジェクト ファイルです。 | |
| 14 | - ファイルを生成した Visual C++ のバージョン情報と、アプリケーション | |
| 15 | - ウィザードで選択したプラットフォーム、構成、およびプロジェクトの機能に関する | |
| 16 | - 情報が記述されています。 | |
| 17 | - | |
| 18 | -QuickHashChecker.cpp | |
| 19 | - これは、メインのアプリケーション ソース ファイルです。 | |
| 20 | - | |
| 21 | -///////////////////////////////////////////////////////////////////////////// | |
| 22 | -その他の標準ファイル : | |
| 23 | - | |
| 24 | -StdAfx.h, StdAfx.cpp | |
| 25 | - これらのファイルは、コンパイル済みヘッダー (PCH) ファイル | |
| 26 | - QuickHashChecker.pch とプリコンパイル済み型ファイル StdAfx.obj を | |
| 27 | - ビルドするために使用します。 | |
| 28 | - | |
| 29 | -///////////////////////////////////////////////////////////////////////////// | |
| 30 | -その他のメモ : | |
| 31 | - | |
| 32 | -AppWizard では "TODO:" コメントを使用して、ユーザーが追加またはカスタマイズする | |
| 33 | -ソース部分を示します。 | |
| 34 | - | |
| 35 | -///////////////////////////////////////////////////////////////////////////// | |
| 36 | - | |
| 37 | - | |
| 38 | - | |
| 39 | - | |
| 1 | +# -*- mode: markdown ; coding: utf-8 -*- | |
| 2 | + | |
| 3 | +README: Quick Hash Checker | |
| 4 | +========================== | |
| 5 | +縺薙?繧「繝励Μ繧ア繝シ繧キ繝ァ繝ウ縺ッ謇玖サス縺ォMD5, SHA1遲峨?隍?焚繝上ャ繧キ繝・蛟、繧貞酔譎ゅ↓貍皮ョ励@縲∬。ィ遉コ縺励∪縺吶? | |
| 6 | + | |
| 7 | +繝上ャ繧キ繝・蛟、縺ョ險育ョ苓?菴薙↓縺ッCrypto++ Library繧剃スソ逕ィ縺励※縺翫j縲√ヰ繧、繝翫Μ繧貞性繧?驟榊ク?黄縺ァ縺ッDLL繝輔ぃ繧、繝ォ繧貞性繧薙〒縺?∪縺吶? | |
| 8 | +蛻ゥ逕ィ縺励※縺?k繝ゥ繧、繝悶Λ繝ェ縺ョ隧ウ邏ー縺ォ縺、縺?※縺ッ縲√?悟茜逕ィ縺励※縺?k繝ゥ繧、繝悶Λ繝ェ縲阪そ繧ッ繧キ繝ァ繝ウ繧堤「コ隱阪@縺ヲ縺上□縺輔>縲 | |
| 9 | + | |
| 10 | +閠??轤ケ | |
| 11 | +----- | |
| 12 | +MD5縺ッ譌「縺ォ螳牙?縺ァ縺ッ縺ゅj縺セ縺帙s縺後?∝コ?¥菴ソ繧上l縺ヲ縺?k縺溘a縺ォ繝?ヵ繧ゥ繝ォ繝医〒SHA1縺ィ萓帙↓邨先棡繧定。ィ遉コ縺励∪縺吶? | |
| 13 | + | |
| 14 | + | |
| 15 | +蛻ゥ逕ィ縺励※縺?k繝ゥ繧、繝悶Λ繝ェ | |
| 16 | +---------------------- | |
| 17 | +螳溯。悟ス「蠑上r蜷ォ繧?驟榊ク?黄縺ァ縺ッ縲ヾQLite3縺ィCrypto++縺ョDLL繝輔ぃ繧、繝ォ繧貞酔譴ア縺励※縺?∪縺吶? | |
| 18 | + | |
| 19 | +* SQLite3.7.5 (2011-01-28 17:03:50 ed759d5a9edb3bba5f48f243df47be29e3fe8cd7") [official site](http://www.sqlite.org/) | |
| 20 | +* Crypto++ Library 5.6.1 [official site](http://www.cryptopp.com/) | |
| 21 | +* Cryptdll.dll (bundled with Windows OS) | |
| 22 | +* Boost 1.46.1 (BoostPro Binary Installer for Visual C++) | |
| 23 | + | |
| 24 | +髢狗匱迺ー蠅 | |
| 25 | +-------- | |
| 26 | +* OS: Windows Vista SP2 32bit | |
| 27 | +* Visual Studio 2005 Standard Edition SP1 (Visual C++ 8.0) | |
| 28 | + | |
| 29 | +License | |
| 30 | +------- | |
| 31 | + Copyright (C) 2010,2011 Yasuhiro ABE <yasu@yasundial.org> | |
| 32 | + | |
| 33 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
| 34 | + you may not use this file except in compliance with the License. | |
| 35 | + You may obtain a copy of the License at | |
| 36 | + | |
| 37 | + http://www.apache.org/licenses/LICENSE-2.0 | |
| 38 | + | |
| 39 | + Unless required by applicable law or agreed to in writing, software | |
| 40 | + distributed under the License is distributed on an "AS IS" BASIS, | |
| 41 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 42 | + See the License for the specific language governing permissions and | |
| 43 | + limitations under the License. | |
| 44 | + | |
| 45 | + |
| @@ -1,44 +1,48 @@ | ||
| 1 | - | |
| 2 | -#include "stdafx.h" | |
| 3 | - | |
| 4 | -sqlite3pp::sqlite3pp(std::string tablename="init.db") : zErrMsg(0), rc(0), db_open(0) { | |
| 5 | - rc = sqlite3_open(tablename.c_str(), &db); | |
| 6 | - if( rc ){ | |
| 7 | - fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); | |
| 8 | - sqlite3_close(db); | |
| 9 | - } | |
| 10 | - db_open=1; | |
| 11 | -} | |
| 12 | - | |
| 13 | -void sqlite3pp::clear() { | |
| 14 | - vcol_head.clear(); | |
| 15 | - vdata.clear(); | |
| 16 | -} | |
| 17 | - | |
| 18 | -int sqlite3pp::exe(std::string s_exe) { | |
| 19 | - rc = sqlite3_get_table( | |
| 20 | - db, /* An open database */ | |
| 21 | - s_exe.c_str(), /* SQL to be executed */ | |
| 22 | - &result, /* Result written to a char *[] that this points to */ | |
| 23 | - &nrow, /* Number of result rows written here */ | |
| 24 | - &ncol, /* Number of result columns written here */ | |
| 25 | - &zErrMsg /* Error msg written here */ | |
| 26 | - ); | |
| 27 | - | |
| 28 | - if(vcol_head.size()<0) { vcol_head.clear(); } | |
| 29 | - if(vdata.size()<0) { vdata.clear(); } | |
| 30 | - | |
| 31 | - if( rc == SQLITE_OK ){ | |
| 32 | - for(int i=0; i < ncol; ++i) | |
| 33 | - vcol_head.push_back(result[i]); /* First row heading */ | |
| 34 | - for(int i=0; i < ncol*nrow; ++i) | |
| 35 | - vdata.push_back(result[ncol+i]); | |
| 36 | - } | |
| 37 | - sqlite3_free_table(result); | |
| 38 | - return rc; | |
| 39 | -} | |
| 40 | - | |
| 41 | -sqlite3pp::~sqlite3pp(){ | |
| 42 | - sqlite3_close(db); | |
| 43 | -} | |
| 44 | - | |
| 1 | + | |
| 2 | +#include "stdafx.h" | |
| 3 | + | |
| 4 | +/** | |
| 5 | + * This file was explained at http://souptonuts.sourceforge.net/readme_sqlite_tutorial.html | |
| 6 | + * | |
| 7 | + * I renamed the class name from SQLITE3 to sqlite3pp. | |
| 8 | + * | |
| 9 | + */ | |
| 10 | +sqlite3pp::sqlite3pp(std::string tablename="init.db") : zErrMsg(0), rc(0), db_open(0) { | |
| 11 | + rc = sqlite3_open(tablename.c_str(), &db); | |
| 12 | + if(rc){ | |
| 13 | + sqlite3_close(db); | |
| 14 | + } | |
| 15 | + db_open=1; | |
| 16 | +} | |
| 17 | + | |
| 18 | +void sqlite3pp::clear() { | |
| 19 | + vcol_head.clear(); | |
| 20 | + vdata.clear(); | |
| 21 | +} | |
| 22 | + | |
| 23 | +int sqlite3pp::exe(std::string s_exe) { | |
| 24 | + rc = sqlite3_get_table(db, /* An open database */ | |
| 25 | + s_exe.c_str(), /* SQL to be executed */ | |
| 26 | + &result, /* Result written to a char *[] that this points to */ | |
| 27 | + &nrow, /* Number of result rows written here */ | |
| 28 | + &ncol, /* Number of result columns written here */ | |
| 29 | + &zErrMsg /* Error msg written here */ | |
| 30 | + ); | |
| 31 | + | |
| 32 | + if(vcol_head.size()<0) { vcol_head.clear(); } | |
| 33 | + if(vdata.size()<0) { vdata.clear(); } | |
| 34 | + | |
| 35 | + if( rc == SQLITE_OK ){ | |
| 36 | + for(int i=0; i < ncol; ++i) | |
| 37 | + vcol_head.push_back(result[i]); /* First row heading */ | |
| 38 | + for(int i=0; i < ncol*nrow; ++i) | |
| 39 | + vdata.push_back(result[ncol+i]); | |
| 40 | + } | |
| 41 | + sqlite3_free_table(result); | |
| 42 | + return rc; | |
| 43 | +} | |
| 44 | + | |
| 45 | +sqlite3pp::~sqlite3pp(){ | |
| 46 | + sqlite3_close(db); | |
| 47 | +} | |
| 48 | + |
| @@ -1,76 +1,76 @@ | ||
| 1 | -// stdafx.h : 標準のシステム インクルード ファイルのインクルード ファイル、または | |
| 2 | -// 参照回数が多く、かつあまり変更されない、プロジェクト専用のインクルード ファイル | |
| 3 | -// を記述します。 | |
| 4 | -// | |
| 5 | - | |
| 6 | -#pragma once | |
| 7 | - | |
| 8 | -#ifndef _WIN32_WINNT // Windows XP 以降のバージョンに固有の機能の使用を許可します。 | |
| 9 | -#define _WIN32_WINNT 0x0501 // これを Windows の他のバージョン向けに適切な値に変更してください。 | |
| 10 | -#endif | |
| 11 | - | |
| 12 | -#include <stdio.h> | |
| 13 | -#include <tchar.h> | |
| 14 | - | |
| 15 | -#include <cstdlib> | |
| 16 | -#include <cwchar> | |
| 17 | -#include <cassert> | |
| 18 | -#include <iomanip> | |
| 19 | -#include <iostream> | |
| 20 | -#include <sstream> | |
| 21 | -#include <string> | |
| 22 | -#include <vector> | |
| 23 | -#include <map> | |
| 24 | - | |
| 25 | -// for boost | |
| 26 | -#include "boost/filesystem.hpp" | |
| 27 | -#include "boost/format.hpp" | |
| 28 | - | |
| 29 | -// for ntfs stream | |
| 30 | -#include <ole2.h> | |
| 31 | -#pragma comment( lib, "ole32.lib" ) | |
| 32 | - | |
| 33 | -// for crypto++ | |
| 34 | -#include "dll.h" | |
| 35 | - | |
| 36 | -// for sqlite3 | |
| 37 | -#include "sqlite3.h" | |
| 38 | -#pragma comment(lib,"sqlite3.lib") | |
| 39 | -#include "sqlite3pp.h" | |
| 40 | - | |
| 41 | -// supporting encryption types. | |
| 42 | -enum yahashtype { | |
| 43 | - md5, sha1, sha256 | |
| 44 | -}; | |
| 45 | - | |
| 46 | -// to save the uuid check results | |
| 47 | -enum uuidstatus { | |
| 48 | - normal, | |
| 49 | - recreated, | |
| 50 | - moved, | |
| 51 | - not_found_on_db, | |
| 52 | - bad // failed to execute setUUID operations. | |
| 53 | -}; | |
| 54 | - | |
| 55 | -// utility: string - string for TCHAR | |
| 56 | -typedef std::basic_string<_TCHAR> tstring; | |
| 57 | - | |
| 58 | -template <typename T> | |
| 59 | -std::string toHex(const T& in, const int width = 2) { | |
| 60 | - std::ostringstream out; | |
| 61 | - out << std::hex << std::setfill('0') << std::setw(width) << in; | |
| 62 | - return out.str(); | |
| 63 | -} | |
| 64 | - | |
| 65 | -// | |
| 66 | -// for my project | |
| 67 | -// | |
| 68 | - | |
| 69 | -#include "yaprops.h" | |
| 70 | -#include "yasqlite3db.h" | |
| 71 | -#include "yantfsstream.h" | |
| 72 | -#include "yahash.h" | |
| 73 | - | |
| 74 | - | |
| 75 | -// it should be the last one. | |
| 76 | -#include "yamain.h" | |
| 1 | +// stdafx.h : 標準のシステム インクルード ファイルのインクルード ファイル、または | |
| 2 | +// 参照回数が多く、かつあまり変更されない、プロジェクト専用のインクルード ファイル | |
| 3 | +// を記述します。 | |
| 4 | +// | |
| 5 | + | |
| 6 | +#pragma once | |
| 7 | + | |
| 8 | +#ifndef _WIN32_WINNT // Windows XP 以降のバージョンに固有の機能の使用を許可します。 | |
| 9 | +#define _WIN32_WINNT 0x0501 // これを Windows の他のバージョン向けに適切な値に変更してください。 | |
| 10 | +#endif | |
| 11 | + | |
| 12 | +#include <stdio.h> | |
| 13 | +#include <tchar.h> | |
| 14 | + | |
| 15 | +#include <cstdlib> | |
| 16 | +#include <cwchar> | |
| 17 | +#include <cassert> | |
| 18 | +#include <iomanip> | |
| 19 | +#include <iostream> | |
| 20 | +#include <sstream> | |
| 21 | +#include <string> | |
| 22 | +#include <vector> | |
| 23 | +#include <map> | |
| 24 | + | |
| 25 | +// for boost | |
| 26 | +#include "boost/filesystem.hpp" | |
| 27 | +#include "boost/format.hpp" | |
| 28 | + | |
| 29 | +// for ntfs stream | |
| 30 | +#include <ole2.h> | |
| 31 | +#pragma comment( lib, "ole32.lib" ) | |
| 32 | + | |
| 33 | +// for crypto++ | |
| 34 | +#include "dll.h" | |
| 35 | + | |
| 36 | +// for sqlite3 | |
| 37 | +#include "sqlite3.h" | |
| 38 | +#pragma comment(lib,"sqlite3.lib") | |
| 39 | +#include "sqlite3pp.h" | |
| 40 | + | |
| 41 | +// supporting encryption types. | |
| 42 | +enum yahashtype { | |
| 43 | + md5, sha1, sha256 | |
| 44 | +}; | |
| 45 | + | |
| 46 | +// to save the uuid check results | |
| 47 | +enum uuidstatus { | |
| 48 | + normal, | |
| 49 | + recreated, | |
| 50 | + moved, | |
| 51 | + not_found_on_db, | |
| 52 | + bad // failed to execute setUUID operations. | |
| 53 | +}; | |
| 54 | + | |
| 55 | +// utility: string - string for TCHAR | |
| 56 | +typedef std::basic_string<_TCHAR> tstring; | |
| 57 | + | |
| 58 | +template <typename T> | |
| 59 | +std::string toHex(const T& in, const int width = 2) { | |
| 60 | + std::ostringstream out; | |
| 61 | + out << std::hex << std::setfill('0') << std::setw(width) << in; | |
| 62 | + return out.str(); | |
| 63 | +} | |
| 64 | + | |
| 65 | +// | |
| 66 | +// for my project | |
| 67 | +// | |
| 68 | + | |
| 69 | +#include "yaprops.h" | |
| 70 | +#include "yasqlite3db.h" | |
| 71 | +#include "yantfsstream.h" | |
| 72 | +#include "yahash.h" | |
| 73 | + | |
| 74 | + | |
| 75 | +// it should be the last one. | |
| 76 | +#include "yamain.h" |
| @@ -1,144 +1,142 @@ | ||
| 1 | -#include "StdAfx.h" | |
| 2 | - | |
| 3 | -yahash::yahash(TCHAR* fp) : file(fp) | |
| 4 | -{ | |
| 5 | -} | |
| 6 | - | |
| 7 | - | |
| 8 | -yahash::~yahash(void) | |
| 9 | -{ | |
| 10 | -} | |
| 11 | - | |
| 12 | - | |
| 13 | -std::string yahash::getDigest(CryptoPP::HashTransformation* hashenc, | |
| 14 | - byte* digest, int digest_len) | |
| 15 | -{ | |
| 16 | - std::ostringstream oret; | |
| 17 | - int max_buff = 8192; | |
| 18 | - byte buff[8192]; | |
| 19 | - boost::filesystem::path p(file); | |
| 20 | - if(boost::filesystem::exists(p)) { | |
| 21 | - HANDLE hl = CreateFile(file, | |
| 22 | - GENERIC_READ, | |
| 23 | - FILE_SHARE_READ, | |
| 24 | - NULL, | |
| 25 | - OPEN_EXISTING, | |
| 26 | - FILE_FLAG_SEQUENTIAL_SCAN, | |
| 27 | - NULL); | |
| 28 | - if(hl != INVALID_HANDLE_VALUE) { | |
| 29 | - BOOL ret; | |
| 30 | - DWORD buff_readsize; | |
| 31 | - do { | |
| 32 | - memset(buff, 0, max_buff); | |
| 33 | - buff_readsize = 0; | |
| 34 | - ret = ReadFile(hl, | |
| 35 | - buff, | |
| 36 | - max_buff, | |
| 37 | - &buff_readsize, | |
| 38 | - NULL); | |
| 39 | - // std::cout << "buff_readsize: " << buff_readsize << std::endl; | |
| 40 | - hashenc->Update(buff, buff_readsize); | |
| 41 | - } while(ret != 0 && buff_readsize != 0); | |
| 42 | - } | |
| 43 | - CloseHandle(hl); | |
| 44 | - hashenc->Final(digest); | |
| 45 | - for(int i=0; i < digest_len; i++) { | |
| 46 | - oret << std::setw(2) << std::setfill('0') << std::hex << (int)(digest[i]); | |
| 47 | - } | |
| 48 | - } | |
| 49 | - return oret.str(); | |
| 50 | -} | |
| 51 | - | |
| 52 | -std::map<int,std::string> yahash::getHash(std::vector<int> types) | |
| 53 | -{ | |
| 54 | - std::map<int, std::string> ret; | |
| 55 | - | |
| 56 | - CryptoPP::SHA1 sha1cpp; | |
| 57 | - byte sha1digest[20]; | |
| 58 | - CryptoPP::SHA256 sha256cpp; | |
| 59 | - byte sha256digest[32]; | |
| 60 | - | |
| 61 | - HMODULE md5_module = LoadLibraryW(L"Cryptdll.dll"); | |
| 62 | - typedef struct | |
| 63 | - { | |
| 64 | - ULONG i[2]; | |
| 65 | - ULONG buf[4]; | |
| 66 | - unsigned char in[64]; | |
| 67 | - unsigned char digest[16]; | |
| 68 | - } MD5_CTX; | |
| 69 | - typedef void (WINAPI *LPFNMD5INIT)(MD5_CTX *); | |
| 70 | - typedef void (WINAPI *LPFNMD5UPDATE)(MD5_CTX *, const unsigned char *, unsigned int); | |
| 71 | - typedef void (WINAPI *LPFNMD5FINAL)(MD5_CTX *); | |
| 72 | - LPFNMD5INIT md5init = (LPFNMD5INIT)GetProcAddress(md5_module, "MD5Init"); | |
| 73 | - LPFNMD5UPDATE md5update = (LPFNMD5UPDATE)GetProcAddress(md5_module, "MD5Update"); | |
| 74 | - LPFNMD5FINAL md5final = (LPFNMD5FINAL)GetProcAddress(md5_module, "MD5Final"); | |
| 75 | - | |
| 76 | - MD5_CTX md5ctx; | |
| 77 | - md5init(&md5ctx); | |
| 78 | - | |
| 79 | - int max_buff = 4098; | |
| 80 | - byte buff[4098]; | |
| 81 | - boost::filesystem::path p(file); | |
| 82 | - if(boost::filesystem::exists(p)) { | |
| 83 | - HANDLE hl = CreateFile(file, | |
| 84 | - GENERIC_READ, | |
| 85 | - FILE_SHARE_READ, | |
| 86 | - NULL, | |
| 87 | - OPEN_EXISTING, | |
| 88 | - FILE_FLAG_SEQUENTIAL_SCAN, | |
| 89 | - NULL); | |
| 90 | - if(hl != INVALID_HANDLE_VALUE) { | |
| 91 | - BOOL ret; | |
| 92 | - DWORD buff_readsize; | |
| 93 | - do { | |
| 94 | - memset(buff, 0, max_buff); | |
| 95 | - buff_readsize = 0; | |
| 96 | - ret = ReadFile(hl, | |
| 97 | - buff, | |
| 98 | - max_buff, | |
| 99 | - &buff_readsize, | |
| 100 | - NULL); | |
| 101 | - // std::cout << "buff_readsize: " << buff_readsize << std::endl; | |
| 102 | - | |
| 103 | - for(unsigned int i=0; i < types.size(); i++) { | |
| 104 | - if(types[i] == sha1) { | |
| 105 | - sha1cpp.Update(buff, buff_readsize); | |
| 106 | - } else if(types[i] == sha256) { | |
| 107 | - sha256cpp.Update(buff, buff_readsize); | |
| 108 | - } else { | |
| 109 | - md5update(&md5ctx, buff, buff_readsize); | |
| 110 | - } | |
| 111 | - } | |
| 112 | - } while(ret != 0 && buff_readsize != 0); | |
| 113 | - } | |
| 114 | - CloseHandle(hl); | |
| 115 | - | |
| 116 | - for(unsigned int i=0; i < types.size(); i++) { | |
| 117 | - if(types[i] == sha1) { | |
| 118 | - std::ostringstream oret; | |
| 119 | - sha1cpp.Final(sha1digest); | |
| 120 | - for(int j=0; j < 20; j++) { | |
| 121 | - oret << std::setw(2) << std::setfill('0') << std::hex << (int)(sha1digest[j]); | |
| 122 | - } | |
| 123 | - ret[types[i]] = oret.str(); | |
| 124 | - } else if(types[i] == sha256) { | |
| 125 | - std::ostringstream oret; | |
| 126 | - sha256cpp.Final(sha256digest); | |
| 127 | - for(int j=0; j < 32; j++) { | |
| 128 | - oret << std::setw(2) << std::setfill('0') << std::hex << (int)(sha256digest[j]); | |
| 129 | - } | |
| 130 | - ret[types[i]] = oret.str(); | |
| 131 | - } else { | |
| 132 | - std::ostringstream oret; | |
| 133 | - md5final(&md5ctx); | |
| 134 | - for(int j=0; j < 16; j++) { | |
| 135 | - oret << std::setw(2) << std::setfill('0') << std::hex << (int)(md5ctx.digest[j]); | |
| 136 | - } | |
| 137 | - ret[types[i]] = oret.str(); | |
| 138 | - } | |
| 139 | - } | |
| 140 | - } | |
| 141 | - | |
| 142 | - FreeLibrary(md5_module); | |
| 143 | - return ret; | |
| 144 | -} | |
| 1 | +#include "StdAfx.h" | |
| 2 | + | |
| 3 | +yahash::yahash(TCHAR* fp) : file(fp) | |
| 4 | +{ | |
| 5 | +} | |
| 6 | + | |
| 7 | + | |
| 8 | +yahash::~yahash(void) | |
| 9 | +{ | |
| 10 | +} | |
| 11 | + | |
| 12 | + | |
| 13 | +std::string yahash::getDigest(CryptoPP::HashTransformation* hashenc, | |
| 14 | + byte* digest, int digest_len) | |
| 15 | +{ | |
| 16 | + std::ostringstream oret; | |
| 17 | + int max_buff = 8192; | |
| 18 | + byte buff[8192]; | |
| 19 | + boost::filesystem::path p(file); | |
| 20 | + if(boost::filesystem::exists(p)) { | |
| 21 | + HANDLE hl = CreateFile(file, | |
| 22 | + GENERIC_READ, | |
| 23 | + FILE_SHARE_READ, | |
| 24 | + NULL, | |
| 25 | + OPEN_EXISTING, | |
| 26 | + FILE_FLAG_SEQUENTIAL_SCAN, | |
| 27 | + NULL); | |
| 28 | + if(hl != INVALID_HANDLE_VALUE) { | |
| 29 | + BOOL ret; | |
| 30 | + DWORD buff_readsize; | |
| 31 | + do { | |
| 32 | + memset(buff, 0, max_buff); | |
| 33 | + buff_readsize = 0; | |
| 34 | + ret = ReadFile(hl, | |
| 35 | + buff, | |
| 36 | + max_buff, | |
| 37 | + &buff_readsize, | |
| 38 | + NULL); | |
| 39 | + hashenc->Update(buff, buff_readsize); | |
| 40 | + } while(ret != 0 && buff_readsize != 0); | |
| 41 | + } | |
| 42 | + CloseHandle(hl); | |
| 43 | + hashenc->Final(digest); | |
| 44 | + for(int i=0; i < digest_len; i++) { | |
| 45 | + oret << std::setw(2) << std::setfill('0') << std::hex << (int)(digest[i]); | |
| 46 | + } | |
| 47 | + } | |
| 48 | + return oret.str(); | |
| 49 | +} | |
| 50 | + | |
| 51 | +std::map<int,std::string> yahash::getHash(std::vector<int> types) | |
| 52 | +{ | |
| 53 | + std::map<int, std::string> ret; | |
| 54 | + | |
| 55 | + CryptoPP::SHA1 sha1cpp; | |
| 56 | + byte sha1digest[20]; | |
| 57 | + CryptoPP::SHA256 sha256cpp; | |
| 58 | + byte sha256digest[32]; | |
| 59 | + | |
| 60 | + HMODULE md5_module = LoadLibraryW(L"Cryptdll.dll"); | |
| 61 | + typedef struct | |
| 62 | + { | |
| 63 | + ULONG i[2]; | |
| 64 | + ULONG buf[4]; | |
| 65 | + unsigned char in[64]; | |
| 66 | + unsigned char digest[16]; | |
| 67 | + } MD5_CTX; | |
| 68 | + typedef void (WINAPI *LPFNMD5INIT)(MD5_CTX *); | |
| 69 | + typedef void (WINAPI *LPFNMD5UPDATE)(MD5_CTX *, const unsigned char *, unsigned int); | |
| 70 | + typedef void (WINAPI *LPFNMD5FINAL)(MD5_CTX *); | |
| 71 | + LPFNMD5INIT md5init = (LPFNMD5INIT)GetProcAddress(md5_module, "MD5Init"); | |
| 72 | + LPFNMD5UPDATE md5update = (LPFNMD5UPDATE)GetProcAddress(md5_module, "MD5Update"); | |
| 73 | + LPFNMD5FINAL md5final = (LPFNMD5FINAL)GetProcAddress(md5_module, "MD5Final"); | |
| 74 | + | |
| 75 | + MD5_CTX md5ctx; | |
| 76 | + md5init(&md5ctx); | |
| 77 | + | |
| 78 | + int max_buff = 4098; | |
| 79 | + byte buff[4098]; | |
| 80 | + boost::filesystem::path p(file); | |
| 81 | + if(boost::filesystem::exists(p)) { | |
| 82 | + HANDLE hl = CreateFile(file, | |
| 83 | + GENERIC_READ, | |
| 84 | + FILE_SHARE_READ, | |
| 85 | + NULL, | |
| 86 | + OPEN_EXISTING, | |
| 87 | + FILE_FLAG_SEQUENTIAL_SCAN, | |
| 88 | + NULL); | |
| 89 | + if(hl != INVALID_HANDLE_VALUE) { | |
| 90 | + BOOL ret; | |
| 91 | + DWORD buff_readsize; | |
| 92 | + do { | |
| 93 | + memset(buff, 0, max_buff); | |
| 94 | + buff_readsize = 0; | |
| 95 | + ret = ReadFile(hl, | |
| 96 | + buff, | |
| 97 | + max_buff, | |
| 98 | + &buff_readsize, | |
| 99 | + NULL); | |
| 100 | + | |
| 101 | + for(unsigned int i=0; i < types.size(); i++) { | |
| 102 | + if(types[i] == sha1) { | |
| 103 | + sha1cpp.Update(buff, buff_readsize); | |
| 104 | + } else if(types[i] == sha256) { | |
| 105 | + sha256cpp.Update(buff, buff_readsize); | |
| 106 | + } else { | |
| 107 | + md5update(&md5ctx, buff, buff_readsize); | |
| 108 | + } | |
| 109 | + } | |
| 110 | + } while(ret != 0 && buff_readsize != 0); | |
| 111 | + } | |
| 112 | + CloseHandle(hl); | |
| 113 | + | |
| 114 | + for(unsigned int i=0; i < types.size(); i++) { | |
| 115 | + if(types[i] == sha1) { | |
| 116 | + std::ostringstream oret; | |
| 117 | + sha1cpp.Final(sha1digest); | |
| 118 | + for(int j=0; j < 20; j++) { | |
| 119 | + oret << std::setw(2) << std::setfill('0') << std::hex << (int)(sha1digest[j]); | |
| 120 | + } | |
| 121 | + ret[types[i]] = oret.str(); | |
| 122 | + } else if(types[i] == sha256) { | |
| 123 | + std::ostringstream oret; | |
| 124 | + sha256cpp.Final(sha256digest); | |
| 125 | + for(int j=0; j < 32; j++) { | |
| 126 | + oret << std::setw(2) << std::setfill('0') << std::hex << (int)(sha256digest[j]); | |
| 127 | + } | |
| 128 | + ret[types[i]] = oret.str(); | |
| 129 | + } else { | |
| 130 | + std::ostringstream oret; | |
| 131 | + md5final(&md5ctx); | |
| 132 | + for(int j=0; j < 16; j++) { | |
| 133 | + oret << std::setw(2) << std::setfill('0') << std::hex << (int)(md5ctx.digest[j]); | |
| 134 | + } | |
| 135 | + ret[types[i]] = oret.str(); | |
| 136 | + } | |
| 137 | + } | |
| 138 | + } | |
| 139 | + | |
| 140 | + FreeLibrary(md5_module); | |
| 141 | + return ret; | |
| 142 | +} |
| @@ -1,111 +1,136 @@ | ||
| 1 | -#include "StdAfx.h" | |
| 2 | - | |
| 3 | -yamain::yamain(TCHAR* _filename, TCHAR* _dbfilename) : filename(_filename), dbfilename(_dbfilename), | |
| 4 | - filepath(boost::filesystem::path(_filename)), | |
| 5 | - dbpath(boost::filesystem::path(_dbfilename)), | |
| 6 | - yafs(new yantfsstream(_filename)), | |
| 7 | - yadb(new yasqlite3db(_filename, _dbfilename)), | |
| 8 | - hash(new yahash(_filename)) | |
| 9 | -{ | |
| 10 | -} | |
| 11 | - | |
| 12 | -yamain::~yamain(void) | |
| 13 | -{ | |
| 14 | - delete yafs; | |
| 15 | - delete yadb; | |
| 16 | -} | |
| 17 | - | |
| 18 | -boolean yamain::deleteData() | |
| 19 | -{ | |
| 20 | - boolean ret = false; | |
| 21 | - | |
| 22 | - return ret; | |
| 23 | -} | |
| 24 | -boolean yamain::createHash() | |
| 25 | -{ | |
| 26 | - boolean ret = false; | |
| 27 | - std::vector<int> hashtypes = yadb->getHashType(); | |
| 28 | - calced_hash = hash->getHash(hashtypes); | |
| 29 | - | |
| 30 | - std::map<int, std::string>::iterator ite; | |
| 31 | - for(ite = calced_hash.begin(); ite != calced_hash.end(); ite++) { | |
| 32 | - std::cout << "createHash(): i,hash: " << ite->first << "," << ite->second << std::endl; | |
| 33 | - boolean rc = yadb->setHash(ite->first, ite->second); | |
| 34 | - if(rc) { | |
| 35 | - rc = true; | |
| 36 | - } | |
| 37 | - } | |
| 38 | - return ret; | |
| 39 | -} | |
| 40 | -boolean yamain::checkHash(boolean update_db) | |
| 41 | -{ | |
| 42 | - boolean ret = false; | |
| 43 | - | |
| 44 | - std::vector<int> hashtypes = yadb->getHashType(); | |
| 45 | - calced_hash = hash->getHash(hashtypes); | |
| 46 | - std::map<int, std::string>::iterator ite; | |
| 47 | - | |
| 48 | - std::map<int, std::string> dbhashmap = yadb->getHash(); | |
| 49 | - std::map<int, std::string>::iterator dbhashmap_ite; | |
| 50 | - for(ite = calced_hash.begin(); ite != calced_hash.end(); ite++) { | |
| 51 | - dbhashmap_ite = dbhashmap.find(ite->first); | |
| 52 | - if(dbhashmap_ite == dbhashmap.end()) { | |
| 53 | - // not found on db | |
| 54 | - std::cout << "not found on db: " << ite->second << std::endl; | |
| 55 | - if(update_db) { | |
| 56 | - std::cout << "update is true: update to '" << ite->second << "'" << std::endl; | |
| 57 | - yadb->setHash(ite->first, ite->second); | |
| 58 | - } | |
| 59 | - } else { | |
| 60 | - // calculated hash result was found on db. | |
| 61 | - std::string diskhash = ite->second; | |
| 62 | - std::string dbhash = dbhashmap[ite->first]; | |
| 63 | - if(diskhash.compare(dbhash) == 0) { | |
| 64 | - std::cout << "diskhash == dbhash" << std::endl; | |
| 65 | - ret = true; | |
| 66 | - } else { | |
| 67 | - std::cout << "diskhash != dbhash" << std::endl; | |
| 68 | - if(update_db) { | |
| 69 | - std::cout << "update is true: value '" << dbhash << "' is updated to '" << diskhash << "'" << std::endl; | |
| 70 | - yadb->setHash(ite->first, diskhash); | |
| 71 | - } | |
| 72 | - } | |
| 73 | - } | |
| 74 | - } | |
| 75 | - return ret; | |
| 76 | -} | |
| 77 | - | |
| 78 | -std::string yamain::getUUIDFromDB() | |
| 79 | -{ | |
| 80 | - std::string ret; | |
| 81 | - ret = yadb->getUUID(); | |
| 82 | - | |
| 83 | - return ret; | |
| 84 | -} | |
| 85 | -std::string yamain::getUUIDFromDisk() | |
| 86 | -{ | |
| 87 | - std::string ret; | |
| 88 | - ret = yafs->getUUID(); | |
| 89 | - | |
| 90 | - return ret; | |
| 91 | -} | |
| 92 | -boolean yamain::setUUIDToDB(std::string uuid) | |
| 93 | -{ | |
| 94 | - boolean ret = yadb->setUUID(uuid); | |
| 95 | - return ret; | |
| 96 | -} | |
| 97 | -boolean yamain::setUUIDToDisk(std::string uuid) | |
| 98 | -{ | |
| 99 | - boolean ret = yafs->setUUID(uuid); | |
| 100 | - return ret; | |
| 101 | -} | |
| 102 | - | |
| 103 | -boolean yamain::checkUUIDonDB(std::string uuid) | |
| 104 | -{ | |
| 105 | - return yadb->existUUID(uuid); | |
| 106 | -} | |
| 107 | - | |
| 108 | -boolean yamain::updateFilepathonDBByUUID(TCHAR* _filename, std::string diskuuid) | |
| 109 | -{ | |
| 110 | - return yadb->updateFilepathByUUID(_filename, diskuuid); | |
| 111 | -} | |
| 1 | +#include "StdAfx.h" | |
| 2 | + | |
| 3 | +yamain::yamain(TCHAR* _filename, TCHAR* _dbfilename) : filename(_filename), dbfilename(_dbfilename), | |
| 4 | + filepath(boost::filesystem::path(_filename)), | |
| 5 | + dbpath(boost::filesystem::path(_dbfilename)), | |
| 6 | + yafs(new yantfsstream(_filename)), | |
| 7 | + yadb(new yasqlite3db(_filename, _dbfilename)), | |
| 8 | + hash(new yahash(_filename)) | |
| 9 | +{ | |
| 10 | + yahashtype_string[(int)md5] = std::string("MD5"); | |
| 11 | + yahashtype_string[(int)sha1] = std::string("SHA1"); | |
| 12 | + yahashtype_string[(int)sha256] = std::string("SHA256"); | |
| 13 | +} | |
| 14 | + | |
| 15 | +yamain::~yamain(void) | |
| 16 | +{ | |
| 17 | + delete yafs; | |
| 18 | + delete yadb; | |
| 19 | +} | |
| 20 | + | |
| 21 | +boolean yamain::deleteData() | |
| 22 | +{ | |
| 23 | + boolean ret = false; | |
| 24 | + | |
| 25 | + return ret; | |
| 26 | +} | |
| 27 | +boolean yamain::createHash() | |
| 28 | +{ | |
| 29 | + boolean ret = false; | |
| 30 | + std::vector<int> hashtypes = yadb->getHashType(); | |
| 31 | + file_hash = hash->getHash(hashtypes); | |
| 32 | + | |
| 33 | + std::map<int, std::string>::iterator ite; | |
| 34 | + for(ite = file_hash.begin(); ite != file_hash.end(); ite++) { | |
| 35 | +#ifdef _DEBUG | |
| 36 | + std::cout << "createHash(): i,hash: " << ite->first << "," << ite->second << std::endl; | |
| 37 | +#endif | |
| 38 | + boolean rc = yadb->setHash(ite->first, ite->second); | |
| 39 | + if(rc) { | |
| 40 | + rc = true; | |
| 41 | + } | |
| 42 | + } | |
| 43 | + return ret; | |
| 44 | +} | |
| 45 | +boolean yamain::checkHash(boolean update_db) | |
| 46 | +{ | |
| 47 | + boolean ret = false; | |
| 48 | + | |
| 49 | + std::vector<int> hashtypes = yadb->getHashType(); | |
| 50 | + file_hash = hash->getHash(hashtypes); | |
| 51 | + std::map<int, std::string>::iterator ite; | |
| 52 | + | |
| 53 | + std::map<int, std::string> dbhashmap = yadb->getHash(); | |
| 54 | + db_hash = dbhashmap; | |
| 55 | + std::map<int, std::string>::iterator dbhashmap_ite; | |
| 56 | + for(ite = file_hash.begin(); ite != file_hash.end(); ite++) { | |
| 57 | + dbhashmap_ite = dbhashmap.find(ite->first); | |
| 58 | + if(dbhashmap_ite == dbhashmap.end()) { | |
| 59 | + // not found on db | |
| 60 | +#ifdef _DEBUG | |
| 61 | + std::cout << "not found on db: " << ite->second << std::endl; | |
| 62 | +#endif | |
| 63 | + if(update_db) { | |
| 64 | +#ifdef _DEBUG | |
| 65 | + std::cout << "update_db is true: update to '" << ite->second << "'" << std::endl; | |
| 66 | +#endif | |
| 67 | + yadb->setHash(ite->first, ite->second); | |
| 68 | + } | |
| 69 | + } else { | |
| 70 | + // calculated hash result was found on db. | |
| 71 | + std::string diskhash = ite->second; | |
| 72 | + std::string dbhash = dbhashmap[ite->first]; | |
| 73 | +#ifdef _DEBUG | |
| 74 | + std::cout << "diskhash: " << diskhash << std::endl; | |
| 75 | + std::cout << "dbhash : " << dbhash << std::endl; | |
| 76 | +#endif | |
| 77 | + if(diskhash.compare(dbhash) == 0) { | |
| 78 | + ret = true; | |
| 79 | + } else { | |
| 80 | + if(update_db) { | |
| 81 | +#ifdef _DEBUG | |
| 82 | + std::cout << "update_db is true: update to '" << diskhash << "'" << std::endl; | |
| 83 | +#endif | |
| 84 | + yadb->setHash(ite->first, diskhash); | |
| 85 | + } | |
| 86 | + } | |
| 87 | + } | |
| 88 | + } | |
| 89 | + // show results | |
| 90 | + for(ite = file_hash.begin(); ite != file_hash.end(); ite++) { | |
| 91 | + // previous value: dbhashmap[ite->first] | |
| 92 | + std::cout << yahashtype_string[ite->first] << "\t: " << ite->second; | |
| 93 | + if(ret) { | |
| 94 | + std::cout << std::endl; | |
| 95 | + } else { | |
| 96 | + std::cout << "(* modified)" << std::endl; | |
| 97 | + } | |
| 98 | + } | |
| 99 | + return ret; | |
| 100 | +} | |
| 101 | + | |
| 102 | +std::string yamain::getUUIDFromDB() | |
| 103 | +{ | |
| 104 | + std::string ret; | |
| 105 | + ret = yadb->getUUID(); | |
| 106 | + | |
| 107 | + return ret; | |
| 108 | +} | |
| 109 | +std::string yamain::getUUIDFromDisk() | |
| 110 | +{ | |
| 111 | + std::string ret; | |
| 112 | + ret = yafs->getUUID(); | |
| 113 | + | |
| 114 | + return ret; | |
| 115 | +} | |
| 116 | +boolean yamain::setUUIDToDB(std::string uuid) | |
| 117 | +{ | |
| 118 | + boolean ret = yadb->setUUID(uuid); | |
| 119 | + return ret; | |
| 120 | +} | |
| 121 | +boolean yamain::setUUIDToDisk(std::string uuid) | |
| 122 | +{ | |
| 123 | + boolean ret = yafs->setUUID(uuid); | |
| 124 | + return ret; | |
| 125 | +} | |
| 126 | + | |
| 127 | +boolean yamain::checkUUIDonDB(std::string uuid) | |
| 128 | +{ | |
| 129 | + return yadb->existUUID(uuid); | |
| 130 | +} | |
| 131 | + | |
| 132 | +boolean yamain::updateFilepathonDBByUUID(TCHAR* _filename, std::string diskuuid) | |
| 133 | +{ | |
| 134 | + return yadb->updateFilepathByUUID(_filename, diskuuid); | |
| 135 | +} | |
| 136 | + |
| @@ -1,32 +1,35 @@ | ||
| 1 | -#pragma once | |
| 2 | - | |
| 3 | -class yamain | |
| 4 | -{ | |
| 5 | -public: | |
| 6 | - yamain(TCHAR* filename, TCHAR* dbfilename); | |
| 7 | - virtual ~yamain(void); | |
| 8 | - | |
| 9 | - virtual boolean deleteData(void); | |
| 10 | - virtual boolean createHash(void); | |
| 11 | - virtual boolean checkHash(boolean update_db = false); | |
| 12 | - | |
| 13 | - virtual std::string getUUIDFromDB(void); | |
| 14 | - virtual std::string getUUIDFromDisk(void); | |
| 15 | - virtual boolean setUUIDToDB(std::string uuid); | |
| 16 | - virtual boolean setUUIDToDisk(std::string uuid); | |
| 17 | - | |
| 18 | - virtual boolean checkUUIDonDB(std::string uuid); | |
| 19 | - virtual boolean updateFilepathonDBByUUID(TCHAR* filename, std::string diskuuid); | |
| 20 | - | |
| 21 | -private: | |
| 22 | - boost::filesystem::path filepath; | |
| 23 | - boost::filesystem::path dbpath; | |
| 24 | - TCHAR* filename; | |
| 25 | - TCHAR* dbfilename; | |
| 26 | - std::string uuid; | |
| 27 | - yantfsstream* yafs; | |
| 28 | - yasqlite3db* yadb; | |
| 29 | - yahash* hash; | |
| 30 | - | |
| 31 | - std::map<int, std::string> calced_hash; | |
| 32 | -}; | |
| 1 | +#pragma once | |
| 2 | + | |
| 3 | +class yamain | |
| 4 | +{ | |
| 5 | +public: | |
| 6 | + yamain(TCHAR* filename, TCHAR* dbfilename); | |
| 7 | + virtual ~yamain(void); | |
| 8 | + | |
| 9 | + virtual boolean deleteData(void); | |
| 10 | + virtual boolean createHash(void); | |
| 11 | + virtual boolean checkHash(boolean update_db = false); | |
| 12 | + | |
| 13 | + virtual std::string getUUIDFromDB(void); | |
| 14 | + virtual std::string getUUIDFromDisk(void); | |
| 15 | + virtual boolean setUUIDToDB(std::string uuid); | |
| 16 | + virtual boolean setUUIDToDisk(std::string uuid); | |
| 17 | + | |
| 18 | + virtual boolean checkUUIDonDB(std::string uuid); | |
| 19 | + virtual boolean updateFilepathonDBByUUID(TCHAR* filename, std::string diskuuid); | |
| 20 | + | |
| 21 | +private: | |
| 22 | + boost::filesystem::path filepath; | |
| 23 | + boost::filesystem::path dbpath; | |
| 24 | + TCHAR* filename; | |
| 25 | + TCHAR* dbfilename; | |
| 26 | + std::string uuid; | |
| 27 | + yantfsstream* yafs; | |
| 28 | + yasqlite3db* yadb; | |
| 29 | + yahash* hash; | |
| 30 | + | |
| 31 | + std::map<int, std::string> yahashtype_string; | |
| 32 | + | |
| 33 | + std::map<int, std::string> file_hash; // results from file | |
| 34 | + std::map<int, std::string> db_hash; // results from db | |
| 35 | +}; |
| @@ -1,64 +1,62 @@ | ||
| 1 | -#include "StdAfx.h" | |
| 2 | - | |
| 3 | -yantfsstream::yantfsstream(TCHAR* _filename) : filename(_filename), | |
| 4 | - filepath(boost::filesystem::path(_filename)), | |
| 5 | - props(new yaprops(_filename)) | |
| 6 | -{ | |
| 7 | -} | |
| 8 | - | |
| 9 | -yantfsstream::~yantfsstream(void) | |
| 10 | -{ | |
| 11 | -} | |
| 12 | - | |
| 13 | -std::string yantfsstream::getUUID() | |
| 14 | -{ | |
| 15 | - std::wstring wcmsg; | |
| 16 | - const wchar_t* wmsg = props->readMsg(); | |
| 17 | - if(wmsg == NULL) { | |
| 18 | - wcmsg = std::wstring(L""); | |
| 19 | - } else { | |
| 20 | - wcmsg = std::wstring(wmsg); | |
| 21 | - } | |
| 22 | - | |
| 23 | - std::wcout << "wcmsg: " << wcmsg << std::endl; | |
| 24 | - std::cout << "wcmsg.size(): " << (int)wcmsg.size() << std::endl; | |
| 25 | - | |
| 26 | - int mbmsg_len = (int)wcmsg.size(); | |
| 27 | - // wprintf(L"wcmsg_len: %d -> 36\n", mbmsg_len); | |
| 28 | - // mbmsg_len = 36; // workaround!! | |
| 29 | - char* mbmsg = new char[mbmsg_len+1]; | |
| 30 | - WideCharToMultiByte(CP_ACP, | |
| 31 | - WC_COMPOSITECHECK, | |
| 32 | - wcmsg.c_str(), | |
| 33 | - -1, | |
| 34 | - mbmsg, | |
| 35 | - mbmsg_len, | |
| 36 | - NULL, | |
| 37 | - NULL); | |
| 38 | - mbmsg[mbmsg_len] = '\0'; | |
| 39 | - std::string ret(mbmsg); | |
| 40 | - std::cout << "yanfsstream::getUUID(): ret: " << ret << std::endl; | |
| 41 | - return ret; | |
| 42 | -} | |
| 43 | - | |
| 44 | -boolean yantfsstream::setUUID(std::string uuid) | |
| 45 | -{ | |
| 46 | - boolean ret = false; | |
| 47 | - | |
| 48 | - wchar_t* uuid_wc = new wchar_t[uuid.size()+1]; | |
| 49 | - MultiByteToWideChar(CP_ACP, | |
| 50 | - MB_PRECOMPOSED, | |
| 51 | - uuid.c_str(), -1, | |
| 52 | - uuid_wc, (int)(uuid.size())); | |
| 53 | - | |
| 54 | - std::cout << "uuid: " << uuid << std::endl; | |
| 55 | - std::cout << "uuid.size(): " << uuid.size() << std::endl; | |
| 56 | - uuid_wc[uuid.size()] = '\0'; | |
| 57 | - std::wcout << L"uuid_wc: " << uuid_wc << std::endl; | |
| 58 | - std::wcout << L"uuid_wc.size():" << uuid_wc << std::endl; | |
| 59 | - props->writeMsg(uuid_wc); | |
| 60 | - | |
| 61 | - delete uuid_wc; // it causes a segfault. | |
| 62 | - ret = true; | |
| 63 | - return ret; | |
| 64 | -} | |
| 1 | +#include "StdAfx.h" | |
| 2 | + | |
| 3 | +yantfsstream::yantfsstream(TCHAR* _filename) : filename(_filename), | |
| 4 | + filepath(boost::filesystem::path(_filename)), | |
| 5 | + props(new yaprops(_filename)) | |
| 6 | +{ | |
| 7 | +} | |
| 8 | + | |
| 9 | +yantfsstream::~yantfsstream(void) | |
| 10 | +{ | |
| 11 | +} | |
| 12 | + | |
| 13 | +std::string yantfsstream::getUUID() | |
| 14 | +{ | |
| 15 | + std::wstring wcmsg; | |
| 16 | + const wchar_t* wmsg = props->readMsg(); | |
| 17 | + if(wmsg == NULL) { | |
| 18 | + wcmsg = std::wstring(L""); | |
| 19 | + } else { | |
| 20 | + wcmsg = std::wstring(wmsg); | |
| 21 | + } | |
| 22 | + int mbmsg_len = (int)wcmsg.size(); | |
| 23 | + char* mbmsg = new char[mbmsg_len+1]; | |
| 24 | + WideCharToMultiByte(CP_ACP, | |
| 25 | + WC_COMPOSITECHECK, | |
| 26 | + wcmsg.c_str(), | |
| 27 | + -1, | |
| 28 | + mbmsg, | |
| 29 | + mbmsg_len, | |
| 30 | + NULL, | |
| 31 | + NULL); | |
| 32 | + mbmsg[mbmsg_len] = '\0'; | |
| 33 | + std::string ret(mbmsg); | |
| 34 | +#ifdef _DEBUG | |
| 35 | + std::cout << "yanfsstream::getUUID(): ret: " << ret << std::endl; | |
| 36 | +#endif | |
| 37 | + return ret; | |
| 38 | +} | |
| 39 | + | |
| 40 | +boolean yantfsstream::setUUID(std::string uuid) | |
| 41 | +{ | |
| 42 | + boolean ret = false; | |
| 43 | + | |
| 44 | + wchar_t* uuid_wc = new wchar_t[uuid.size()+1]; | |
| 45 | + MultiByteToWideChar(CP_ACP, | |
| 46 | + MB_PRECOMPOSED, | |
| 47 | + uuid.c_str(), -1, | |
| 48 | + uuid_wc, (int)(uuid.size())); | |
| 49 | + | |
| 50 | + uuid_wc[uuid.size()] = '\0'; | |
| 51 | +#ifdef _DEBUG | |
| 52 | + std::cout << "uuid: " << uuid << std::endl; | |
| 53 | + std::cout << "uuid.size(): " << uuid.size() << std::endl; | |
| 54 | + std::wcout << L"uuid_wc: " << uuid_wc << std::endl; | |
| 55 | + std::wcout << L"uuid_wc.size():" << uuid_wc << std::endl; | |
| 56 | +#endif | |
| 57 | + props->writeMsg(uuid_wc); | |
| 58 | + | |
| 59 | + delete uuid_wc; // it causes a segfault. | |
| 60 | + ret = true; | |
| 61 | + return ret; | |
| 62 | +} |
| @@ -1,184 +1,184 @@ | ||
| 1 | -#include "StdAfx.h" | |
| 2 | - | |
| 3 | -yaprops::yaprops(TCHAR* f) : filename(f), pPropSetStg(NULL), pPropStg(NULL), fmtid(FMTID_SummaryInformation) | |
| 4 | -{ | |
| 5 | -} | |
| 6 | - | |
| 7 | -yaprops::~yaprops(void) | |
| 8 | -{ | |
| 9 | -} | |
| 10 | - | |
| 11 | -HRESULT yaprops::getIPropertySetStorage(void) | |
| 12 | -{ | |
| 13 | - HRESULT hr; | |
| 14 | - IPropertySetStorage* pPropSetStg = NULL; | |
| 15 | - | |
| 16 | - hr = StgOpenStorageEx(this->filename, | |
| 17 | - STGM_READWRITE | STGM_SHARE_EXCLUSIVE, | |
| 18 | - STGFMT_FILE, | |
| 19 | - 0, // preserved. It must be zero. | |
| 20 | - NULL, // pointer to STGOPTIONS object | |
| 21 | - 0, // preserved. It must be zero. | |
| 22 | - IID_IPropertySetStorage, | |
| 23 | - reinterpret_cast<void**>(&pPropSetStg)); | |
| 24 | - | |
| 25 | - this->pPropSetStg = pPropSetStg; | |
| 26 | - return hr; | |
| 27 | -} | |
| 28 | - | |
| 29 | -HRESULT yaprops::getIPropertySetStorageReader(void) | |
| 30 | -{ | |
| 31 | - HRESULT hr; | |
| 32 | - IPropertySetStorage* pPropSetStg = NULL; | |
| 33 | - | |
| 34 | - hr = StgOpenStorageEx(this->filename, | |
| 35 | - STGM_READ | STGM_SHARE_EXCLUSIVE, | |
| 36 | - STGFMT_FILE, | |
| 37 | - 0, // preserved. It must be zero. | |
| 38 | - NULL, // pointer to STGOPTIONS object | |
| 39 | - 0, // preserved. It must be zero. | |
| 40 | - IID_IPropertySetStorage, | |
| 41 | - reinterpret_cast<void**>(&pPropSetStg)); | |
| 42 | - | |
| 43 | - this->pPropSetStg = pPropSetStg; | |
| 44 | - return hr; | |
| 45 | -} | |
| 46 | - | |
| 47 | - | |
| 48 | -HRESULT yaprops::openIPropertyStorage() | |
| 49 | -{ | |
| 50 | - HRESULT hr; | |
| 51 | - IPropertyStorage* pPropStg = NULL; | |
| 52 | - hr = this->pPropSetStg->Open(fmtid, | |
| 53 | - STGM_READWRITE | STGM_SHARE_EXCLUSIVE, | |
| 54 | - &pPropStg); | |
| 55 | - | |
| 56 | - this->pPropStg = pPropStg; | |
| 57 | - return hr; | |
| 58 | -} | |
| 59 | - | |
| 60 | -HRESULT yaprops::createIPropertyStorage() | |
| 61 | -{ | |
| 62 | - HRESULT hr; | |
| 63 | - IPropertyStorage* pPropStg = NULL; | |
| 64 | - hr = this->pPropSetStg->Create(fmtid, | |
| 65 | - NULL, | |
| 66 | - PROPSETFLAG_DEFAULT, | |
| 67 | - STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, | |
| 68 | - &pPropStg); | |
| 69 | - | |
| 70 | - this->pPropStg = pPropStg; | |
| 71 | - return hr; | |
| 72 | -} | |
| 73 | - | |
| 74 | -HRESULT yaprops::readIPropertyStorage() | |
| 75 | -{ | |
| 76 | - HRESULT hr; | |
| 77 | - IPropertyStorage* pPropStg = NULL; | |
| 78 | - hr = this->pPropSetStg->Open(fmtid, | |
| 79 | - STGM_READ | STGM_SHARE_EXCLUSIVE, | |
| 80 | - &pPropStg); | |
| 81 | - | |
| 82 | - this->pPropStg = pPropStg; | |
| 83 | - return hr; | |
| 84 | -} | |
| 85 | - | |
| 86 | - | |
| 87 | -void yaprops::writeMsg(const wchar_t* message) | |
| 88 | -{ | |
| 89 | - HRESULT hr; | |
| 90 | - PROPSPEC propspec; | |
| 91 | - PROPVARIANT propWrite; | |
| 92 | - | |
| 93 | - try { | |
| 94 | - hr = getIPropertySetStorage(); | |
| 95 | - if(FAILED(hr) || this->pPropSetStg == NULL) { | |
| 96 | - throw L"Failed to initialize IPropertySetStorage"; | |
| 97 | - } | |
| 98 | - hr = openIPropertyStorage(); | |
| 99 | - if(FAILED(hr) || this->pPropStg == NULL) { | |
| 100 | - hr = createIPropertyStorage(); | |
| 101 | - if(FAILED(hr) || this->pPropStg == NULL) { | |
| 102 | - throw L"Failed to initialize IPropertyStorage"; | |
| 103 | - } | |
| 104 | - } | |
| 105 | - | |
| 106 | - propspec.ulKind = PRSPEC_PROPID; | |
| 107 | - propspec.propid = PIDSI_COMMENTS; | |
| 108 | - propWrite.vt = VT_LPWSTR; | |
| 109 | - propWrite.pwszVal = (LPWSTR)message; | |
| 110 | - hr = this->pPropStg->WriteMultiple(1, &propspec, &propWrite, PID_FIRST_USABLE); | |
| 111 | - if(FAILED(hr)) { | |
| 112 | - throw L"Failed to write message"; | |
| 113 | - } | |
| 114 | - hr = this->pPropStg->Commit(STGC_DEFAULT); | |
| 115 | - if(FAILED(hr)) { | |
| 116 | - throw L"Failed to commit the write transcation"; | |
| 117 | - } | |
| 118 | - } catch(const WCHAR *pwszError) { | |
| 119 | - std::wcout << L"failed to update: " << pwszError << std::endl; | |
| 120 | - throw pwszError; | |
| 121 | - } | |
| 122 | - if(this->pPropStg != NULL) { | |
| 123 | - this->pPropStg->Release(); | |
| 124 | - this->pPropStg = NULL; | |
| 125 | - } | |
| 126 | - if(this->pPropSetStg != NULL) { | |
| 127 | - this->pPropSetStg->Release(); | |
| 128 | - this->pPropSetStg = NULL; | |
| 129 | - } | |
| 130 | -} | |
| 131 | - | |
| 132 | -const wchar_t* yaprops::readMsg(void) | |
| 133 | -{ | |
| 134 | - wchar_t* retmsg; | |
| 135 | - HRESULT hr; | |
| 136 | - PROPSPEC propspec; | |
| 137 | - PROPVARIANT propRead; | |
| 138 | - try { | |
| 139 | - hr = getIPropertySetStorageReader(); | |
| 140 | - if(FAILED(hr) || this->pPropSetStg == NULL) { | |
| 141 | - throw L"Failed to initialize IPropertySetStorage"; | |
| 142 | - } | |
| 143 | - hr = readIPropertyStorage(); | |
| 144 | - if(FAILED(hr) || this->pPropStg == NULL) { | |
| 145 | - throw L"Failed to initialize IPropertyStorage"; | |
| 146 | - } | |
| 147 | - | |
| 148 | - propspec.ulKind = PRSPEC_PROPID; | |
| 149 | - propspec.propid = PIDSI_COMMENTS; | |
| 150 | - hr = this->pPropStg->ReadMultiple(1, &propspec, &propRead); | |
| 151 | - if(FAILED(hr)) { | |
| 152 | - throw L"Failed to read ReadMultiple"; | |
| 153 | - } | |
| 154 | - } catch(const WCHAR *pwszError) { | |
| 155 | - std::wcout << L"pwszError happend: " << pwszError << std::endl; | |
| 156 | - return NULL; | |
| 157 | - } | |
| 158 | - size_t retmsg_len = 0; | |
| 159 | - switch(propRead.vt) { | |
| 160 | - case VT_EMPTY: | |
| 161 | - retmsg = NULL; | |
| 162 | - break; | |
| 163 | - case VT_LPSTR: | |
| 164 | - // My Windows XP (SP3) reachs here. | |
| 165 | - // UNICODE is enabled, but Japanese char through the extended panel. | |
| 166 | - retmsg = new wchar_t[strlen(propRead.pszVal) + 1]; // '+ 1' is essential for the '\0' terminator. | |
| 167 | - mbstowcs_s(&retmsg_len, retmsg, strlen(propRead.pszVal) + 1, propRead.pszVal, _TRUNCATE); | |
| 168 | - break; | |
| 169 | - case VT_LPWSTR: | |
| 170 | - retmsg = (wchar_t*)propRead.pwszVal; | |
| 171 | - break; | |
| 172 | - default: | |
| 173 | - retmsg = L""; | |
| 174 | - } | |
| 175 | - if(this->pPropSetStg != NULL) { | |
| 176 | - this->pPropSetStg->Release(); | |
| 177 | - this->pPropSetStg = NULL; | |
| 178 | - } | |
| 179 | - if(this->pPropStg != NULL) { | |
| 180 | - this->pPropStg->Release(); | |
| 181 | - this->pPropStg = NULL; | |
| 182 | - } | |
| 183 | - return retmsg; | |
| 184 | -} | |
| 1 | +#include "StdAfx.h" | |
| 2 | + | |
| 3 | +yaprops::yaprops(TCHAR* f) : filename(f), pPropSetStg(NULL), pPropStg(NULL), fmtid(FMTID_SummaryInformation) | |
| 4 | +{ | |
| 5 | +} | |
| 6 | + | |
| 7 | +yaprops::~yaprops(void) | |
| 8 | +{ | |
| 9 | +} | |
| 10 | + | |
| 11 | +HRESULT yaprops::getIPropertySetStorage(void) | |
| 12 | +{ | |
| 13 | + HRESULT hr; | |
| 14 | + IPropertySetStorage* pPropSetStg = NULL; | |
| 15 | + | |
| 16 | + hr = StgOpenStorageEx(this->filename, | |
| 17 | + STGM_READWRITE | STGM_SHARE_EXCLUSIVE, | |
| 18 | + STGFMT_FILE, | |
| 19 | + 0, // preserved. It must be zero. | |
| 20 | + NULL, // pointer to STGOPTIONS object | |
| 21 | + 0, // preserved. It must be zero. | |
| 22 | + IID_IPropertySetStorage, | |
| 23 | + reinterpret_cast<void**>(&pPropSetStg)); | |
| 24 | + | |
| 25 | + this->pPropSetStg = pPropSetStg; | |
| 26 | + return hr; | |
| 27 | +} | |
| 28 | + | |
| 29 | +HRESULT yaprops::getIPropertySetStorageReader(void) | |
| 30 | +{ | |
| 31 | + HRESULT hr; | |
| 32 | + IPropertySetStorage* pPropSetStg = NULL; | |
| 33 | + | |
| 34 | + hr = StgOpenStorageEx(this->filename, | |
| 35 | + STGM_READ | STGM_SHARE_EXCLUSIVE, | |
| 36 | + STGFMT_FILE, | |
| 37 | + 0, // preserved. It must be zero. | |
| 38 | + NULL, // pointer to STGOPTIONS object | |
| 39 | + 0, // preserved. It must be zero. | |
| 40 | + IID_IPropertySetStorage, | |
| 41 | + reinterpret_cast<void**>(&pPropSetStg)); | |
| 42 | + | |
| 43 | + this->pPropSetStg = pPropSetStg; | |
| 44 | + return hr; | |
| 45 | +} | |
| 46 | + | |
| 47 | + | |
| 48 | +HRESULT yaprops::openIPropertyStorage() | |
| 49 | +{ | |
| 50 | + HRESULT hr; | |
| 51 | + IPropertyStorage* pPropStg = NULL; | |
| 52 | + hr = this->pPropSetStg->Open(fmtid, | |
| 53 | + STGM_READWRITE | STGM_SHARE_EXCLUSIVE, | |
| 54 | + &pPropStg); | |
| 55 | + | |
| 56 | + this->pPropStg = pPropStg; | |
| 57 | + return hr; | |
| 58 | +} | |
| 59 | + | |
| 60 | +HRESULT yaprops::createIPropertyStorage() | |
| 61 | +{ | |
| 62 | + HRESULT hr; | |
| 63 | + IPropertyStorage* pPropStg = NULL; | |
| 64 | + hr = this->pPropSetStg->Create(fmtid, | |
| 65 | + NULL, | |
| 66 | + PROPSETFLAG_DEFAULT, | |
| 67 | + STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, | |
| 68 | + &pPropStg); | |
| 69 | + | |
| 70 | + this->pPropStg = pPropStg; | |
| 71 | + return hr; | |
| 72 | +} | |
| 73 | + | |
| 74 | +HRESULT yaprops::readIPropertyStorage() | |
| 75 | +{ | |
| 76 | + HRESULT hr; | |
| 77 | + IPropertyStorage* pPropStg = NULL; | |
| 78 | + hr = this->pPropSetStg->Open(fmtid, | |
| 79 | + STGM_READ | STGM_SHARE_EXCLUSIVE, | |
| 80 | + &pPropStg); | |
| 81 | + | |
| 82 | + this->pPropStg = pPropStg; | |
| 83 | + return hr; | |
| 84 | +} | |
| 85 | + | |
| 86 | + | |
| 87 | +void yaprops::writeMsg(const wchar_t* message) | |
| 88 | +{ | |
| 89 | + HRESULT hr; | |
| 90 | + PROPSPEC propspec; | |
| 91 | + PROPVARIANT propWrite; | |
| 92 | + | |
| 93 | + try { | |
| 94 | + hr = getIPropertySetStorage(); | |
| 95 | + if(FAILED(hr) || this->pPropSetStg == NULL) { | |
| 96 | + throw L"Failed to initialize IPropertySetStorage"; | |
| 97 | + } | |
| 98 | + hr = openIPropertyStorage(); | |
| 99 | + if(FAILED(hr) || this->pPropStg == NULL) { | |
| 100 | + hr = createIPropertyStorage(); | |
| 101 | + if(FAILED(hr) || this->pPropStg == NULL) { | |
| 102 | + throw L"Failed to initialize IPropertyStorage"; | |
| 103 | + } | |
| 104 | + } | |
| 105 | + | |
| 106 | + propspec.ulKind = PRSPEC_PROPID; | |
| 107 | + propspec.propid = PIDSI_COMMENTS; | |
| 108 | + propWrite.vt = VT_LPWSTR; | |
| 109 | + propWrite.pwszVal = (LPWSTR)message; | |
| 110 | + hr = this->pPropStg->WriteMultiple(1, &propspec, &propWrite, PID_FIRST_USABLE); | |
| 111 | + if(FAILED(hr)) { | |
| 112 | + throw L"Failed to write message"; | |
| 113 | + } | |
| 114 | + hr = this->pPropStg->Commit(STGC_DEFAULT); | |
| 115 | + if(FAILED(hr)) { | |
| 116 | + throw L"Failed to commit the write transcation"; | |
| 117 | + } | |
| 118 | + } catch(const WCHAR *pwszError) { | |
| 119 | + std::wcerr << L"NTFS Stream cannot be used: " << pwszError << std::endl; | |
| 120 | + throw pwszError; | |
| 121 | + } | |
| 122 | + if(this->pPropStg != NULL) { | |
| 123 | + this->pPropStg->Release(); | |
| 124 | + this->pPropStg = NULL; | |
| 125 | + } | |
| 126 | + if(this->pPropSetStg != NULL) { | |
| 127 | + this->pPropSetStg->Release(); | |
| 128 | + this->pPropSetStg = NULL; | |
| 129 | + } | |
| 130 | +} | |
| 131 | + | |
| 132 | +const wchar_t* yaprops::readMsg(void) | |
| 133 | +{ | |
| 134 | + wchar_t* retmsg; | |
| 135 | + HRESULT hr; | |
| 136 | + PROPSPEC propspec; | |
| 137 | + PROPVARIANT propRead; | |
| 138 | + try { | |
| 139 | + hr = getIPropertySetStorageReader(); | |
| 140 | + if(FAILED(hr) || this->pPropSetStg == NULL) { | |
| 141 | + throw L"Failed to initialize IPropertySetStorage"; | |
| 142 | + } | |
| 143 | + hr = readIPropertyStorage(); | |
| 144 | + if(FAILED(hr) || this->pPropStg == NULL) { | |
| 145 | + throw L"Failed to initialize IPropertyStorage"; | |
| 146 | + } | |
| 147 | + | |
| 148 | + propspec.ulKind = PRSPEC_PROPID; | |
| 149 | + propspec.propid = PIDSI_COMMENTS; | |
| 150 | + hr = this->pPropStg->ReadMultiple(1, &propspec, &propRead); | |
| 151 | + if(FAILED(hr)) { | |
| 152 | + throw L"Failed to read ReadMultiple"; | |
| 153 | + } | |
| 154 | + } catch(const WCHAR *pwszError) { | |
| 155 | + std::wcerr << L"NTFS Stream cannot be used: " << pwszError << std::endl; | |
| 156 | + return NULL; | |
| 157 | + } | |
| 158 | + size_t retmsg_len = 0; | |
| 159 | + switch(propRead.vt) { | |
| 160 | + case VT_EMPTY: | |
| 161 | + retmsg = NULL; | |
| 162 | + break; | |
| 163 | + case VT_LPSTR: | |
| 164 | + // My Windows XP (SP3) reachs here. | |
| 165 | + // UNICODE is enabled, but Japanese char throguh the extended panel. | |
| 166 | + retmsg = new wchar_t[strlen(propRead.pszVal) + 1]; // '+ 1' is essential for the '\0' terminator. | |
| 167 | + mbstowcs_s(&retmsg_len, retmsg, strlen(propRead.pszVal) + 1, propRead.pszVal, _TRUNCATE); | |
| 168 | + break; | |
| 169 | + case VT_LPWSTR: | |
| 170 | + retmsg = (wchar_t*)propRead.pwszVal; | |
| 171 | + break; | |
| 172 | + default: | |
| 173 | + retmsg = L""; | |
| 174 | + } | |
| 175 | + if(this->pPropSetStg != NULL) { | |
| 176 | + this->pPropSetStg->Release(); | |
| 177 | + this->pPropSetStg = NULL; | |
| 178 | + } | |
| 179 | + if(this->pPropStg != NULL) { | |
| 180 | + this->pPropStg->Release(); | |
| 181 | + this->pPropStg = NULL; | |
| 182 | + } | |
| 183 | + return retmsg; | |
| 184 | +} |
| @@ -1,266 +1,274 @@ | ||
| 1 | - | |
| 2 | -#include "StdAfx.h" | |
| 3 | - | |
| 4 | -yasqlite3db::yasqlite3db(_TCHAR* _filename, _TCHAR* _dbfilename) : dbfilename(_dbfilename), | |
| 5 | - filename(_filename), | |
| 6 | - filepath(boost::filesystem::path(_filename)), | |
| 7 | - dbfilepath(boost::filesystem::path(_dbfilename)), | |
| 8 | - uuid(std::string("")), | |
| 9 | - tfilepath(tstring(_filename)), | |
| 10 | - tdbfilepath(tstring(_dbfilename)) | |
| 11 | -{ | |
| 12 | - escaped_filepath = boost::filesystem::path(escape_sqlite3t(tfilepath)); | |
| 13 | - db = new sqlite3pp(dbfilepath.string().c_str()); | |
| 14 | - | |
| 15 | - std::cerr << "dbname is :" << dbfilepath << std::endl; | |
| 16 | - int sqlrc = db->exe("select uuid from uuid"); | |
| 17 | - std::cout << "result of the correct select query: " << sqlrc << std::endl; // rc == 0 | |
| 18 | - if(sqlrc == SQLITE_OK) { | |
| 19 | - // found uuid | |
| 20 | - //uuid = db->vdata.at(0); | |
| 21 | - } else { | |
| 22 | - // not found uuid by filepath | |
| 23 | - uuid = std::string(""); | |
| 24 | - // create tables | |
| 25 | - sqlrc = db->exe("create table uuid (filepath text, uuid text, primary key(uuid,filepath))"); | |
| 26 | - if(sqlrc == SQLITE_ERROR) { | |
| 27 | - std::cerr << "failed to crete table uuid." << std::endl; | |
| 28 | - } | |
| 29 | - sqlrc = db->exe("create table hash (uuid text, type text, value text, primary key(uuid,type))"); | |
| 30 | - if(sqlrc == SQLITE_ERROR) { | |
| 31 | - std::cerr << "failed to crete table hash." << std::endl; | |
| 32 | - } | |
| 33 | - sqlrc = db->exe("create table hashtype (uuid text, type integer, primary key(uuid,type))"); | |
| 34 | - if(sqlrc == SQLITE_ERROR) { | |
| 35 | - std::cerr << "failed to crete table uuid." << std::endl; | |
| 36 | - } | |
| 37 | - | |
| 38 | - // set the initial default hash types. | |
| 39 | - std::ostringstream s; | |
| 40 | - s << "insert into hashtype (uuid,type) values ('*'," << md5 << ")"; | |
| 41 | - sqlrc = db->exe(s.str()); | |
| 42 | - if(sqlrc == SQLITE_ERROR) { | |
| 43 | - std::cerr << "failed to insert hash table." << std::endl; | |
| 44 | - } | |
| 45 | - std::ostringstream ss; | |
| 46 | - ss << "insert into hashtype (uuid,type) values ('*'," << sha1 << ")"; | |
| 47 | - sqlrc = db->exe(ss.str()); | |
| 48 | - if(sqlrc == SQLITE_ERROR) { | |
| 49 | - std::cerr << "failed to insert hash table." << std::endl; | |
| 50 | - } | |
| 51 | - } | |
| 52 | - db->clear(); | |
| 53 | -} | |
| 54 | - | |
| 55 | -yasqlite3db::~yasqlite3db(void) | |
| 56 | -{ | |
| 57 | - delete db; | |
| 58 | -} | |
| 59 | - | |
| 60 | -std::string yasqlite3db::getUUID() | |
| 61 | -{ | |
| 62 | - std::cout << "begin yasqlite3db::getUUID()" << std::endl; | |
| 63 | - std::ostringstream s; | |
| 64 | - | |
| 65 | - s << "select uuid from uuid where filepath = '" << escaped_filepath << "'"; | |
| 66 | - std::cout << "sql: " << s.str() << std::endl; | |
| 67 | - int rc = db->exe(s.str()); | |
| 68 | - if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 69 | - std::cout << "getUUID() == ok." << std::endl; | |
| 70 | - | |
| 71 | - uuid = db->vdata.at(0); | |
| 72 | - std::cout << "uuid: " << uuid << std::endl; | |
| 73 | - } else { | |
| 74 | - std::cout << "failed to execute sql" << std::endl; | |
| 75 | - } | |
| 76 | - db->clear(); | |
| 77 | - return uuid; | |
| 78 | -} | |
| 79 | - | |
| 80 | -boolean yasqlite3db::setUUID(std::string _uuid) | |
| 81 | -{ | |
| 82 | - std::cout << "begin yasqlite3db::setUUID()" << std::endl; | |
| 83 | - boolean ret = false; | |
| 84 | - uuid = _uuid; | |
| 85 | - std::ostringstream s; | |
| 86 | - | |
| 87 | - s << "insert into uuid (uuid,filepath) values ('" << uuid << "','" << escaped_filepath << "')"; | |
| 88 | - std::cout << "exec sql: " << s.str() << std::endl; | |
| 89 | - int rc = db->exe(s.str()); | |
| 90 | - std::cout << "rc: " << rc << std::endl; | |
| 91 | - if(rc == SQLITE_OK) { | |
| 92 | - std::cout << "success" << std::endl; | |
| 93 | - ret = true; | |
| 94 | - } else { | |
| 95 | - std::cout << "failed, then update" << std::endl; | |
| 96 | - std::ostringstream s; | |
| 97 | - | |
| 98 | - s << "update uuid set uuid = '" << uuid << "' where filepath = '" << escaped_filepath << "'"; | |
| 99 | - std::cout << "exec sql: " << s.str() << std::endl; | |
| 100 | - int rc = db->exe(s.str()); | |
| 101 | - if(rc == SQLITE_OK) { | |
| 102 | - ret = true; | |
| 103 | - } | |
| 104 | - } | |
| 105 | - db->clear(); | |
| 106 | - return ret; | |
| 107 | -} | |
| 108 | - | |
| 109 | -boolean yasqlite3db::existUUID(std::string uuid) | |
| 110 | -{ | |
| 111 | - std::cout << "begin yasqlite3db::existUUID()" << std::endl; | |
| 112 | - boolean ret = false; | |
| 113 | - std::ostringstream s; | |
| 114 | - s << "select uuid from uuid where uuid = '" << uuid << "'"; | |
| 115 | - int rc = db->exe(s.str()); | |
| 116 | - if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 117 | - ret = true; | |
| 118 | - } | |
| 119 | - db->clear(); | |
| 120 | - return ret; | |
| 121 | -} | |
| 122 | - | |
| 123 | -boolean yasqlite3db::updateFilepathByUUID(_TCHAR* _filepath, std::string _uuid) | |
| 124 | -{ | |
| 125 | - std::cout << "begin yasqlite3db::updateFilepathByUUID()" << std::endl; | |
| 126 | - boolean ret = false; | |
| 127 | - std::ostringstream s; | |
| 128 | - | |
| 129 | - boost::filesystem::path _filepath_escaped(escape_sqlite3t(tfilepath)); | |
| 130 | - s << "update uuid set filepath = '" << _filepath_escaped << "' where uuid = '" << _uuid << "'"; | |
| 131 | - std::cout << "sql: " << s.str() << std::endl; | |
| 132 | - int rc = db->exe(s.str()); | |
| 133 | - if(rc == SQLITE_OK) { | |
| 134 | - filename = _filepath; | |
| 135 | - filepath = boost::filesystem::path(filename); | |
| 136 | - tfilepath = tstring(filename); | |
| 137 | - escaped_filepath = boost::filesystem::path(escape_sqlite3t(tfilepath)); | |
| 138 | - | |
| 139 | - uuid = _uuid; | |
| 140 | - ret = true; | |
| 141 | - } | |
| 142 | - db->clear(); | |
| 143 | - return ret; | |
| 144 | -} | |
| 145 | - | |
| 146 | -/** | |
| 147 | - * | |
| 148 | - * @return std::map of type and value. | |
| 149 | - **/ | |
| 150 | -std::map<int, std::string> yasqlite3db::getHash() | |
| 151 | -{ | |
| 152 | - std::map<int, std::string> hash; | |
| 153 | - std::ostringstream s; | |
| 154 | - s << "select type,value from hash where uuid = '" << uuid << "'"; | |
| 155 | - std::cout << "sql: " << s.str() << std::endl; | |
| 156 | - int rc = db->exe(s.str()); | |
| 157 | - if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 158 | - for(size_t i=0; i < db->vdata.size(); i++) { | |
| 159 | - std::cout << "hash::type,value: " << db->vdata.at(i) << std::endl; | |
| 160 | - int type = atoi(db->vdata.at(i).c_str()); | |
| 161 | - i++; | |
| 162 | - hash[type] = db->vdata.at(i); | |
| 163 | - } | |
| 164 | - } | |
| 165 | - db->clear(); | |
| 166 | - return hash; | |
| 167 | -} | |
| 168 | - | |
| 169 | -boolean yasqlite3db::setHash(int type, std::string hash_value) | |
| 170 | -{ | |
| 171 | - boolean ret = false; | |
| 172 | - std::ostringstream s; | |
| 173 | - s << "insert into hash (uuid,type,value) values ('" << uuid << "'," << type << ",'" << hash_value << "')"; | |
| 174 | - std::cout << "sql: " << s.str() << std::endl; | |
| 175 | - int rc = db->exe(s.str()); | |
| 176 | - if(rc == SQLITE_OK) { | |
| 177 | - ret = true; | |
| 178 | - } else { | |
| 179 | - std::ostringstream s; | |
| 180 | - s << "update hash set value = '" << hash_value << "' where uuid = '" << uuid << "' and type = " << type; | |
| 181 | - std::cout << "sql: " << s.str() << std::endl; | |
| 182 | - rc = db->exe(s.str()); | |
| 183 | - if(rc == SQLITE_OK) { | |
| 184 | - ret = true; | |
| 185 | - } | |
| 186 | - } | |
| 187 | - db->clear(); | |
| 188 | - return ret; | |
| 189 | -} | |
| 190 | - | |
| 191 | -std::vector<int> yasqlite3db::getHashType() | |
| 192 | -{ | |
| 193 | - std::vector<int> ret; | |
| 194 | - std::ostringstream s; | |
| 195 | - s << "select type from hashtype where uuid = '" << uuid << "'"; | |
| 196 | - int rc = db->exe(s.str()); | |
| 197 | - if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 198 | - for(size_t i=0; i < db->vdata.size(); i++) { | |
| 199 | - ret.push_back(atoi(db->vdata.at(i).c_str())); | |
| 200 | - std::cout << "hashtype::type: " << db->vdata.at(i) << std::endl; | |
| 201 | - } | |
| 202 | - } else if(rc == SQLITE_OK && db->vdata.size() == 0) { | |
| 203 | - rc = db->exe("select type from hashtype where uuid = '*'"); | |
| 204 | - if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 205 | - for(size_t i=0; i < db->vdata.size(); i++) { | |
| 206 | - ret.push_back(atoi(db->vdata.at(i).c_str())); | |
| 207 | - std::cout << "hashtype::default type: " << db->vdata.at(i) << std::endl; | |
| 208 | - } | |
| 209 | - } | |
| 210 | - } | |
| 211 | - db->clear(); | |
| 212 | - return ret; | |
| 213 | -} | |
| 214 | - | |
| 215 | -boolean yasqlite3db::deleteAllHash(std::string uuid) | |
| 216 | -{ | |
| 217 | - boolean ret = false; | |
| 218 | - | |
| 219 | - return ret; | |
| 220 | -} | |
| 221 | - | |
| 222 | -// utility: escape | |
| 223 | -std::string yasqlite3db::escape_sqlite3(const std::string& query) | |
| 224 | -{ | |
| 225 | - std::string s = query; | |
| 226 | - for(size_t i=0; i<query.size(); i+=2) { | |
| 227 | - i = s.find("'", i); | |
| 228 | - if(i < 0) { | |
| 229 | - break; | |
| 230 | - } | |
| 231 | - s.replace(i, 1, "''"); | |
| 232 | - } | |
| 233 | - return s; | |
| 234 | -} | |
| 235 | - | |
| 236 | -std::wstring yasqlite3db::escape_sqlite3w(const std::wstring& query) | |
| 237 | -{ | |
| 238 | - std::wstring s = query; | |
| 239 | - std::wcout << L"escape_sqlite3w::query: " << query << std::endl; | |
| 240 | - for(size_t i=0; i<query.size(); i+=2) { | |
| 241 | - i = s.find(L"'", i); | |
| 242 | - std::cout << "i: " << i << std::endl; | |
| 243 | - if(i < 0) { | |
| 244 | - break; | |
| 245 | - } | |
| 246 | - s.replace(i, 1, L"''"); | |
| 247 | - } | |
| 248 | - return s; | |
| 249 | -} | |
| 250 | - | |
| 251 | -tstring yasqlite3db::escape_sqlite3t(const tstring& query) | |
| 252 | -{ | |
| 253 | - tstring s = query; | |
| 254 | - std::cout << "query.size(): " << query.size() << std::endl; | |
| 255 | - for(size_t i=0; i < query.size(); i=i+2) { | |
| 256 | - i = s.find(_T("'"), i); | |
| 257 | - std::cout << "i: " << i << std::endl; | |
| 258 | - if(i < 0 || i > query.size()) { // might be bug of std::wstring::find() | |
| 259 | - break; | |
| 260 | - } | |
| 261 | - | |
| 262 | - s.replace(i, 1, _T("''")); | |
| 263 | - } | |
| 264 | - return s; | |
| 265 | -} | |
| 266 | - | |
| 1 | + | |
| 2 | +#include "StdAfx.h" | |
| 3 | + | |
| 4 | +yasqlite3db::yasqlite3db(_TCHAR* _filename, _TCHAR* _dbfilename) : dbfilename(_dbfilename), | |
| 5 | + filename(_filename), | |
| 6 | + filepath(boost::filesystem::path(_filename)), | |
| 7 | + dbfilepath(boost::filesystem::path(_dbfilename)), | |
| 8 | + uuid(std::string("")), | |
| 9 | + tfilepath(tstring(_filename)), | |
| 10 | + tdbfilepath(tstring(_dbfilename)) | |
| 11 | +{ | |
| 12 | + escaped_filepath = boost::filesystem::path(escape_sqlite3t(tfilepath)); | |
| 13 | + db = new sqlite3pp(dbfilepath.string().c_str()); | |
| 14 | + | |
| 15 | + int sqlrc = db->exe("select uuid from uuid"); | |
| 16 | + if(sqlrc == SQLITE_OK) { | |
| 17 | + // found uuid | |
| 18 | + //uuid = db->vdata.at(0); | |
| 19 | + } else { | |
| 20 | + // not found uuid by filepath | |
| 21 | + uuid = std::string(""); | |
| 22 | + // create tables | |
| 23 | + sqlrc = db->exe("create table uuid (filepath text, uuid text, primary key(uuid,filepath))"); | |
| 24 | + if(sqlrc == SQLITE_ERROR) { | |
| 25 | +#ifdef _DEBUG | |
| 26 | + std::cerr << "failed to crete table uuid." << std::endl; | |
| 27 | +#endif | |
| 28 | + } | |
| 29 | + sqlrc = db->exe("create table hash (uuid text, type text, value text, primary key(uuid,type))"); | |
| 30 | + if(sqlrc == SQLITE_ERROR) { | |
| 31 | +#ifdef _DEBUG | |
| 32 | + std::cerr << "failed to crete table hash." << std::endl; | |
| 33 | +#endif | |
| 34 | + } | |
| 35 | + sqlrc = db->exe("create table hashtype (uuid text, type integer, primary key(uuid,type))"); | |
| 36 | + if(sqlrc == SQLITE_ERROR) { | |
| 37 | +#ifdef _DEBUG | |
| 38 | + std::cerr << "failed to crete table uuid." << std::endl; | |
| 39 | +#endif | |
| 40 | + } | |
| 41 | + | |
| 42 | + // set the initial default hash types. | |
| 43 | + std::ostringstream s; | |
| 44 | + s << "insert into hashtype (uuid,type) values ('*'," << md5 << ")"; | |
| 45 | + sqlrc = db->exe(s.str()); | |
| 46 | + if(sqlrc == SQLITE_ERROR) { | |
| 47 | +#ifdef _DEBUG | |
| 48 | + std::cerr << "failed to insert hash table." << std::endl; | |
| 49 | +#endif | |
| 50 | + } | |
| 51 | + std::ostringstream ss; | |
| 52 | + ss << "insert into hashtype (uuid,type) values ('*'," << sha1 << ")"; | |
| 53 | + sqlrc = db->exe(ss.str()); | |
| 54 | + if(sqlrc == SQLITE_ERROR) { | |
| 55 | +#ifdef _DEBUG | |
| 56 | + std::cerr << "failed to insert hash table." << std::endl; | |
| 57 | +#endif | |
| 58 | + } | |
| 59 | + } | |
| 60 | + db->clear(); | |
| 61 | +} | |
| 62 | + | |
| 63 | +yasqlite3db::~yasqlite3db(void) | |
| 64 | +{ | |
| 65 | + delete db; | |
| 66 | +} | |
| 67 | + | |
| 68 | +std::string yasqlite3db::getUUID() | |
| 69 | +{ | |
| 70 | + std::ostringstream s; | |
| 71 | + s << "select uuid from uuid where filepath = '" << escaped_filepath << "'"; | |
| 72 | +#ifdef _DEBUG | |
| 73 | + std::cout << "sql: " << s.str() << std::endl; | |
| 74 | +#endif | |
| 75 | + int rc = db->exe(s.str()); | |
| 76 | + if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 77 | + uuid = db->vdata.at(0); | |
| 78 | + } else { | |
| 79 | +#ifdef _DEBUG | |
| 80 | + std::cerr << "failed to execute sql" << std::endl; | |
| 81 | +#endif | |
| 82 | + } | |
| 83 | + db->clear(); | |
| 84 | +#ifdef _DEBUG | |
| 85 | + std::cerr << "getUUID(): " << uuid << std::endl; | |
| 86 | +#endif | |
| 87 | + return uuid; | |
| 88 | +} | |
| 89 | + | |
| 90 | +boolean yasqlite3db::setUUID(std::string _uuid) | |
| 91 | +{ | |
| 92 | + boolean ret = false; | |
| 93 | + uuid = _uuid; | |
| 94 | + std::ostringstream s; | |
| 95 | + | |
| 96 | + s << "insert into uuid (uuid,filepath) values ('" << uuid << "','" << escaped_filepath << "')"; | |
| 97 | +#ifdef _DEBUG | |
| 98 | + std::cout << "exec sql: " << s.str() << std::endl; | |
| 99 | +#endif | |
| 100 | + int rc = db->exe(s.str()); | |
| 101 | + if(rc == SQLITE_OK) { | |
| 102 | + ret = true; | |
| 103 | + } else { | |
| 104 | + std::ostringstream s; | |
| 105 | + s << "update uuid set uuid = '" << uuid << "' where filepath = '" << escaped_filepath << "'"; | |
| 106 | +#ifdef _DEBUG | |
| 107 | + std::cerr << "exec sql: " << s.str() << std::endl; | |
| 108 | +#endif | |
| 109 | + int rc = db->exe(s.str()); | |
| 110 | + if(rc == SQLITE_OK) { | |
| 111 | + ret = true; | |
| 112 | + } | |
| 113 | + } | |
| 114 | + db->clear(); | |
| 115 | + return ret; | |
| 116 | +} | |
| 117 | + | |
| 118 | +boolean yasqlite3db::existUUID(std::string uuid) | |
| 119 | +{ | |
| 120 | + boolean ret = false; | |
| 121 | + std::ostringstream s; | |
| 122 | + s << "select uuid from uuid where uuid = '" << uuid << "'"; | |
| 123 | + int rc = db->exe(s.str()); | |
| 124 | + if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 125 | + ret = true; | |
| 126 | + } | |
| 127 | + db->clear(); | |
| 128 | + return ret; | |
| 129 | +} | |
| 130 | + | |
| 131 | +boolean yasqlite3db::updateFilepathByUUID(_TCHAR* _filepath, std::string _uuid) | |
| 132 | +{ | |
| 133 | + boolean ret = false; | |
| 134 | + std::ostringstream s; | |
| 135 | + | |
| 136 | + boost::filesystem::path _filepath_escaped(escape_sqlite3t(tfilepath)); | |
| 137 | + s << "update uuid set filepath = '" << _filepath_escaped << "' where uuid = '" << _uuid << "'"; | |
| 138 | +#ifdef _DEBUG | |
| 139 | + std::cerr << "sql: " << s.str() << std::endl; | |
| 140 | +#endif | |
| 141 | + int rc = db->exe(s.str()); | |
| 142 | + if(rc == SQLITE_OK) { | |
| 143 | + filename = _filepath; | |
| 144 | + filepath = boost::filesystem::path(filename); | |
| 145 | + tfilepath = tstring(filename); | |
| 146 | + escaped_filepath = boost::filesystem::path(escape_sqlite3t(tfilepath)); | |
| 147 | + uuid = _uuid; | |
| 148 | + ret = true; | |
| 149 | + } | |
| 150 | + db->clear(); | |
| 151 | + return ret; | |
| 152 | +} | |
| 153 | + | |
| 154 | +/** | |
| 155 | + * | |
| 156 | + * @return std::map of type and value. | |
| 157 | + **/ | |
| 158 | +std::map<int, std::string> yasqlite3db::getHash() | |
| 159 | +{ | |
| 160 | + std::map<int, std::string> hash; | |
| 161 | + std::ostringstream s; | |
| 162 | + s << "select type,value from hash where uuid = '" << uuid << "'"; | |
| 163 | +#ifdef _DEBUG | |
| 164 | + std::cerr << "sql: " << s.str() << std::endl; | |
| 165 | +#endif | |
| 166 | + int rc = db->exe(s.str()); | |
| 167 | + if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 168 | + for(size_t i=0; i < db->vdata.size(); i++) { | |
| 169 | + int type = atoi(db->vdata.at(i).c_str()); | |
| 170 | + i++; | |
| 171 | + hash[type] = db->vdata.at(i); | |
| 172 | + } | |
| 173 | + } | |
| 174 | + db->clear(); | |
| 175 | + return hash; | |
| 176 | +} | |
| 177 | + | |
| 178 | +boolean yasqlite3db::setHash(int type, std::string hash_value) | |
| 179 | +{ | |
| 180 | + boolean ret = false; | |
| 181 | + std::ostringstream s; | |
| 182 | + s << "insert into hash (uuid,type,value) values ('" << uuid << "'," << type << ",'" << hash_value << "')"; | |
| 183 | +#ifdef _DEBUG | |
| 184 | + std::cerr << "sql: " << s.str() << std::endl; | |
| 185 | +#endif | |
| 186 | + int rc = db->exe(s.str()); | |
| 187 | + if(rc == SQLITE_OK) { | |
| 188 | + ret = true; | |
| 189 | + } else { | |
| 190 | + std::ostringstream s; | |
| 191 | + s << "update hash set value = '" << hash_value << "' where uuid = '" << uuid << "' and type = " << type; | |
| 192 | +#ifdef _DEBUG | |
| 193 | + std::cout << "sql: " << s.str() << std::endl; | |
| 194 | +#endif | |
| 195 | + rc = db->exe(s.str()); | |
| 196 | + if(rc == SQLITE_OK) { | |
| 197 | + ret = true; | |
| 198 | + } | |
| 199 | + } | |
| 200 | + db->clear(); | |
| 201 | + return ret; | |
| 202 | +} | |
| 203 | + | |
| 204 | +std::vector<int> yasqlite3db::getHashType() | |
| 205 | +{ | |
| 206 | + std::vector<int> ret; | |
| 207 | + std::ostringstream s; | |
| 208 | + s << "select type from hashtype where uuid = '" << uuid << "'"; | |
| 209 | +#ifdef _DEBUG | |
| 210 | + std::cerr << "sql: " << s.str() << std::endl; | |
| 211 | +#endif | |
| 212 | + int rc = db->exe(s.str()); | |
| 213 | + if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 214 | + for(size_t i=0; i < db->vdata.size(); i++) { | |
| 215 | + ret.push_back(atoi(db->vdata.at(i).c_str())); | |
| 216 | + } | |
| 217 | + } else if(rc == SQLITE_OK && db->vdata.size() == 0) { | |
| 218 | + rc = db->exe("select type from hashtype where uuid = '*'"); | |
| 219 | + if(rc == SQLITE_OK && db->vdata.size() > 0) { | |
| 220 | + for(size_t i=0; i < db->vdata.size(); i++) { | |
| 221 | + ret.push_back(atoi(db->vdata.at(i).c_str())); | |
| 222 | + } | |
| 223 | + } | |
| 224 | + } | |
| 225 | + db->clear(); | |
| 226 | + return ret; | |
| 227 | +} | |
| 228 | + | |
| 229 | +boolean yasqlite3db::deleteAllHash(std::string uuid) | |
| 230 | +{ | |
| 231 | + boolean ret = false; | |
| 232 | + return ret; | |
| 233 | +} | |
| 234 | + | |
| 235 | +// utility: escape | |
| 236 | +std::string yasqlite3db::escape_sqlite3(const std::string& query) | |
| 237 | +{ | |
| 238 | + std::string s = query; | |
| 239 | + for(size_t i=0; i<query.size(); i+=2) { | |
| 240 | + i = s.find("'", i); | |
| 241 | + if(i < 0) { | |
| 242 | + break; | |
| 243 | + } | |
| 244 | + s.replace(i, 1, "''"); | |
| 245 | + } | |
| 246 | + return s; | |
| 247 | +} | |
| 248 | + | |
| 249 | +std::wstring yasqlite3db::escape_sqlite3w(const std::wstring& query) | |
| 250 | +{ | |
| 251 | + std::wstring s = query; | |
| 252 | + for(size_t i=0; i<query.size(); i+=2) { | |
| 253 | + i = s.find(L"'", i); | |
| 254 | + if(i < 0) { | |
| 255 | + break; | |
| 256 | + } | |
| 257 | + s.replace(i, 1, L"''"); | |
| 258 | + } | |
| 259 | + return s; | |
| 260 | +} | |
| 261 | + | |
| 262 | +tstring yasqlite3db::escape_sqlite3t(const tstring& query) | |
| 263 | +{ | |
| 264 | + tstring s = query; | |
| 265 | + for(size_t i=0; i < query.size(); i=i+2) { | |
| 266 | + i = s.find(_T("'"), i); | |
| 267 | + if(i < 0 || i > query.size()) { // might be bug of std::wstring::find() | |
| 268 | + break; | |
| 269 | + } | |
| 270 | + s.replace(i, 1, _T("''")); | |
| 271 | + } | |
| 272 | + return s; | |
| 273 | +} | |
| 274 | + |