OpenClonk
C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck Struct Reference

#include <C4StartupModsDlg.h>

Inheritance diagram for C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck:
[legend]
Collaboration diagram for C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck:
[legend]

Public Member Functions

 LocalDiscoveryCheck (ModInfo &mod)
 
void Start ()
 

Public Attributes

std::string basePath
 
bool needsCheck { true }
 
bool installed { false }
 
bool atLeastOneFileExisted { false }
 

Protected Member Functions

void Execute () override
 
void SignalStop ()
 
void Stop ()
 
bool IsStarted ()
 
bool IsStopSignaled ()
 
virtual bool IsSelfDestruct ()
 

Protected Attributes

ModInfo & mod
 

Detailed Description

Definition at line 186 of file C4StartupModsDlg.h.

Constructor & Destructor Documentation

◆ LocalDiscoveryCheck()

C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::LocalDiscoveryCheck ( ModInfo &  mod)
inline

Definition at line 193 of file C4StartupModsDlg.h.

Member Function Documentation

◆ Execute()

void C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::Execute ( )
overrideprotectedvirtual

Implements StdThread.

Definition at line 1079 of file C4StartupModsDlg.cpp.

1080 {
1081  assert(installed);
1082 
1083  for (auto fileIterator = mod.files.begin(); fileIterator != mod.files.end();)
1084  {
1085  auto &file = *fileIterator;
1086  bool fileExists = false;
1087 
1088  // Check if the file already exists.
1089  if (!file.sha1.empty())
1090  {
1091  const std::string &hashString = file.sha1;
1092  BYTE hash[SHA_DIGEST_LENGTH];
1093  const std::string filePath = basePath + DirectorySeparator + file.name;
1094  if (GetFileSHA1(filePath.c_str(), hash))
1095  {
1096  fileExists = true;
1097 
1098  // Match hashes (string against byte array).
1099  const size_t byteLen = 2;
1100  size_t index = 0;
1101  for (size_t offset = 0; offset < hashString.size(); offset += byteLen, index += 1)
1102  {
1103  // Oddly, the indices of the byte array do not correspond 1-to-1 to a standard sha1 string.
1104  const size_t hashIndex = (index / 4 * 4) + (3 - (index % 4));
1105  const BYTE &byte = hash[hashIndex];
1106 
1107  const std::string byteStr = hashString.substr(offset, byteLen);
1108  unsigned char byteStrValue = static_cast<unsigned char> (std::stoi(byteStr, nullptr, 16));
1109 
1110  if (byteStrValue != byte)
1111  {
1112  fileExists = false;
1113  break;
1114  }
1115  }
1116  }
1117  }
1118 
1119  if (fileExists)
1120  {
1121  fileIterator = mod.files.erase(fileIterator);
1122  atLeastOneFileExisted = true;
1123  }
1124  else
1125  {
1126  ++fileIterator;
1127  }
1128  }
1129 
1130  // Fire-once check done.
1131  needsCheck = false;
1133 }
bool GetFileSHA1(const char *szFilename, BYTE *pSHA1)
Definition: CStdFile.cpp:381
#define DirectorySeparator
uint8_t BYTE
#define SHA_DIGEST_LENGTH
Definition: SHA1.h:42
void SignalStop()

References atLeastOneFileExisted, basePath, DirectorySeparator, GetFileSHA1(), installed, mod, needsCheck, SHA_DIGEST_LENGTH, and StdThread::SignalStop().

Here is the call graph for this function:

◆ IsSelfDestruct()

virtual bool StdThread::IsSelfDestruct ( )
inlineprotectedvirtualinherited

Reimplemented in CPNGSaveThread.

Definition at line 338 of file StdScheduler.h.

338 { return false; } // whether thread should delete itself after execution finished

◆ IsStarted()

bool StdThread::IsStarted ( )
inlineinherited

Definition at line 332 of file StdScheduler.h.

332 { return fStarted; }

◆ IsStopSignaled()

bool StdThread::IsStopSignaled ( )
protectedinherited

Definition at line 342 of file StdScheduler.cpp.

343 {
344  return fStopSignaled;
345 }

◆ SignalStop()

void StdThread::SignalStop ( )
inherited

Definition at line 298 of file StdScheduler.cpp.

299 {
300  // Not running?
301  if (!fStarted) return;
302  // Set flag
303  fStopSignaled = true;
304 }

Referenced by CPNGSaveThread::Execute(), C4StartupModsLocalModDiscovery::Execute(), and Execute().

Here is the caller graph for this function:

◆ Start()

void C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::Start ( )
inline

Definition at line 194 of file C4StartupModsDlg.h.

194 { StdThread::Start(); }
bool Start()

References StdThread::Start().

Here is the call graph for this function:

◆ Stop()

void StdThread::Stop ( )
inherited

Definition at line 306 of file StdScheduler.cpp.

307 {
308  // Not running?
309  if (!fStarted) return;
310  // Set flag
311  fStopSignaled = true;
312 #ifdef HAVE_WINTHREAD
313  // Wait for thread to terminate itself
314  HANDLE hThread = reinterpret_cast<HANDLE>(iThread);
315  if (WaitForSingleObject(hThread, 10000) == WAIT_TIMEOUT)
316  // ... or kill it in case it refuses to do so
317  TerminateThread(hThread, -1);
318 #elif defined(HAVE_PTHREAD)
319  // wait for thread to terminate itself
320  // (whithout security - let's trust these unwashed hackers for once)
321  pthread_join(Thread, nullptr);
322 #endif
323  fStarted = false;
324  // ok
325  return;
326 }

Referenced by StdThread::Start(), and StdThread::~StdThread().

Here is the caller graph for this function:

Member Data Documentation

◆ atLeastOneFileExisted

bool C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::atLeastOneFileExisted { false }

Definition at line 191 of file C4StartupModsDlg.h.

Referenced by Execute().

◆ basePath

std::string C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::basePath

Definition at line 188 of file C4StartupModsDlg.h.

Referenced by Execute().

◆ installed

bool C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::installed { false }

Definition at line 190 of file C4StartupModsDlg.h.

Referenced by Execute().

◆ mod

ModInfo& C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::mod
protected

Definition at line 196 of file C4StartupModsDlg.h.

Referenced by Execute().

◆ needsCheck

bool C4StartupModsDownloader::ModInfo::LocalDiscoveryCheck::needsCheck { true }

Definition at line 189 of file C4StartupModsDlg.h.

Referenced by Execute().


The documentation for this struct was generated from the following files: