summaryrefslogtreecommitdiff
path: root/support/dktools/Dk4FcsThread.cpp
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/dktools/Dk4FcsThread.cpp
Initial commit
Diffstat (limited to 'support/dktools/Dk4FcsThread.cpp')
-rw-r--r--support/dktools/Dk4FcsThread.cpp244
1 files changed, 244 insertions, 0 deletions
diff --git a/support/dktools/Dk4FcsThread.cpp b/support/dktools/Dk4FcsThread.cpp
new file mode 100644
index 0000000000..5afedd6720
--- /dev/null
+++ b/support/dktools/Dk4FcsThread.cpp
@@ -0,0 +1,244 @@
+/*
+ WARNING: This file was generated by dkct.
+ Changes you make here will be lost if dkct is run again!
+ You should modify the original source and run dkct on it.
+ Original source: Dk4FcsThread.cpt
+*/
+
+/*
+Copyright (C) 2015, Dirk Krause
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above opyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+* Neither the name of the author nor the names of contributors may be used
+ to endorse or promote products derived from this software without specific
+ prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED.
+IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/** @file Dk4FcsThread.cpp The Dk4FcsThread module.
+*/
+
+
+#line 108 "Dk4FcsThread.cpt"
+
+
+#include "dk4mem.h"
+#include "wxdkfcs.h"
+
+
+
+static
+void
+ctx_collection_init(dk4fcs_ctx_t *ptr)
+{
+ dk4mem_reset(ptr, sizeof(dk4fcs_ctx_t), NULL);
+#if DK4_HAVE_OPENSSL_MD5_H
+ MD5_Init(&(ptr->md5));
+#endif
+#if DK4_HAVE_OPENSSL_RIPEMD_H
+ RIPEMD160_Init(&(ptr->ripemd160));
+#endif
+#if DK4_HAVE_OPENSSL_SHA_H
+ SHA1_Init(&(ptr->sha1));
+#if DK4_HAVE_SHA224
+ SHA224_Init(&(ptr->sha224));
+#endif
+#if DK4_HAVE_SHA256
+ SHA256_Init(&(ptr->sha256));
+#endif
+#if DK4_HAVE_SHA384
+ SHA384_Init(&(ptr->sha384));
+#endif
+#if DK4_HAVE_SHA512
+ SHA512_Init(&(ptr->sha512));
+#endif
+#endif
+}
+
+
+
+static
+void
+ctx_collection_add(dk4fcs_ctx_t *ptr, void *data, size_t sz)
+{
+#if DK4_HAVE_OPENSSL_MD5_H
+ MD5_Update(&(ptr->md5), data, sz);
+#endif
+#if DK4_HAVE_OPENSSL_RIPEMD_H
+ RIPEMD160_Update(&(ptr->ripemd160), data, sz);
+#endif
+#if DK4_HAVE_OPENSSL_SHA_H
+ SHA1_Update(&(ptr->sha1), data, sz);
+#if DK4_HAVE_SHA224
+ SHA224_Update(&(ptr->sha224), data, sz);
+#endif
+#if DK4_HAVE_SHA256
+ SHA256_Update(&(ptr->sha256), data, sz);
+#endif
+#if DK4_HAVE_SHA384
+ SHA384_Update(&(ptr->sha384), data, sz);
+#endif
+#if DK4_HAVE_SHA512
+ SHA512_Update(&(ptr->sha512), data, sz);
+#endif
+#endif
+}
+
+
+
+static
+void
+ctx_collection_finish(dk4fcs_ctx_t *ptr)
+{
+#if DK4_HAVE_OPENSSL_MD5_H
+ MD5_Final(&(ptr->md5bytes[0]), &(ptr->md5));
+#endif
+#if DK4_HAVE_OPENSSL_RIPEMD_H
+ RIPEMD160_Final(&(ptr->ripemd160bytes[0]), &(ptr->ripemd160));
+#endif
+#if DK4_HAVE_OPENSSL_SHA_H
+ SHA1_Final(&(ptr->sha1bytes[0]), &(ptr->sha1));
+#if DK4_HAVE_SHA224
+ SHA224_Final(&(ptr->sha224bytes[0]), &(ptr->sha224));
+#endif
+#if DK4_HAVE_SHA256
+ SHA256_Final(&(ptr->sha256bytes[0]), &(ptr->sha256));
+#endif
+#if DK4_HAVE_SHA384
+ SHA384_Final(&(ptr->sha384bytes[0]), &(ptr->sha384));
+#endif
+#if DK4_HAVE_SHA512
+ SHA512_Final(&(ptr->sha512bytes[0]), &(ptr->sha512));
+#endif
+#endif
+}
+
+
+
+Dk4FcsThread::Dk4FcsThread(
+ wxFile *wxf,
+ Dk4WxProcessingController *proCo,
+ dk4fcs_ctx_t *ctx
+)
+{
+ pWxFile = wxf;
+ pProCo = proCo;
+ pCtx = ctx;
+}
+
+
+
+void *
+Dk4FcsThread::Entry()
+{
+ unsigned char buf[4096];
+ void *back = NULL;
+ wxFileOffset fileSize = (wxFileOffset)0UL;
+ wxFileOffset summary = (wxFileOffset)0UL;
+ size_t rdb = 0;
+ int gv = 0;
+ int ogv = 0;
+ bool cc = true; // Flag: Can continue
+ bool succ = true; // Flag: Success
+
+
+
+#line 230 "Dk4FcsThread.cpt"
+ /* Initialize variables.
+ */
+ fileSize = pWxFile->Length();
+ ctx_collection_init(pCtx);
+
+
+#line 235 "Dk4FcsThread.cpt"
+ /* Run in a loop.
+ */
+ do {
+ if (pProCo->canContinue()) {
+
+#line 239 "Dk4FcsThread.cpt"
+ rdb = pWxFile->Read(buf, sizeof(buf));
+ if (0 < rdb) {
+
+#line 241 "Dk4FcsThread.cpt"
+ ctx_collection_add(pCtx, buf, rdb);
+
+#line 242 "Dk4FcsThread.cpt"
+ summary += (wxFileOffset)rdb;
+ if ((wxFileOffset)0UL < fileSize) {
+ if (summary < fileSize) {
+ gv = (int)((1000.0 * (double)summary) / (double)fileSize);
+ } else {
+ gv = 1000;
+ }
+ } else {
+ gv = 1000;
+ }
+ if (gv != ogv) {
+
+#line 253 "Dk4FcsThread.cpt"
+ pProCo->setGaugeValue(gv);
+ ogv = gv;
+ }
+ } else {
+
+#line 257 "Dk4FcsThread.cpt"
+ if (summary != fileSize) {
+ succ = false;
+
+#line 259 "Dk4FcsThread.cpt"
+ }
+ cc = false;
+ }
+ } else {
+
+#line 263 "Dk4FcsThread.cpt"
+ cc = false;
+ succ = false; // Aborted by user.
+ }
+ } while(cc);
+
+
+#line 268 "Dk4FcsThread.cpt"
+ /* Finish contexts.
+ */
+ ctx_collection_finish(pCtx);
+
+
+#line 272 "Dk4FcsThread.cpt"
+ /* End processsing
+ */
+ pProCo->endProcessing(succ);
+
+
+#line 276 "Dk4FcsThread.cpt"
+ return back;
+}
+
+
+
+void
+Dk4FcsThread::OnExit()
+{
+
+}
+
+