Guest User

Untitled

a guest
May 6th, 2021
40
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "FOrbitDataTask.h"
  4. #include "FileManagementUtils.h"
  5. #include "Misc/ScopeLock.h"
  6. #include "StringUtils.h"
  7.  
  8. //FCriticalSection FOrbitDataTask::Mutex = nullptr;
  9.  
  10. FOrbitDataTask::FOrbitDataTask(uint32 OrbitID, FString Filename, FString FileDirectory, FString DataToBeStored, FCriticalSection& Mutex)
  11. {  
  12.     this->OrbitID = OrbitID;
  13.     this->Filename = Filename;
  14.     this->FileDirectory = FileDirectory;   
  15.     this->DataToBeStored = DataToBeStored;
  16.     this->Mutex = &Mutex;
  17.  
  18. }
  19.  
  20. FOrbitDataTask::~FOrbitDataTask()
  21. {
  22. }
  23.  
  24. void FOrbitDataTask::DoWork()
  25. {
  26.     FGenericTask::DoWork();
  27.    
  28.     TArray<FString> FileData;  
  29.    
  30.     {
  31.         FScopeLock Lock(Mutex);
  32.        
  33.         UE_LOG(LogTemp, Warning, TEXT("%s is requesting the lock..."),
  34.             *this->GetStatId().GetName().ToString()
  35.         );
  36.  
  37.         if(IFileManagementUtils::FileExists(Filename, FileDirectory))
  38.         {
  39.             IFileManagementUtils::LoadTextDataFrom(Filename, FileDirectory, FileData);
  40.  
  41.             FString SearchableInfo = TEXT("OrbitData = ");         
  42.             SearchableInfo += IStringUtils::UnsignedIntToString(OrbitID);
  43.                        
  44.             for (int Index = 0; Index <= FileData.Num() - 1; Index++)
  45.             {
  46.                 bool bItContains = FileData[Index].Contains(SearchableInfo);
  47.  
  48.                 bItContains = !bItContains;
  49.  
  50.                 if (bItContains && (Index < FileData.Num() - 1))
  51.                 {
  52.                     FileData.Insert(DataToBeStored, Index + 1);
  53.                 }
  54.                 else
  55.                 {
  56.                     if (Index == FileData.Num() - 1)
  57.                     {
  58.                         FileData.Add(DataToBeStored);
  59.                     }
  60.                 }
  61.  
  62.                 break;
  63.             }
  64.         }
  65.         else
  66.         {
  67.             FileData.Add(DataToBeStored);
  68.         }      
  69.            
  70.         IFileManagementUtils::CreateTextFileFrom(Filename, FileDirectory, FileData, true);
  71.        
  72.         UE_LOG(LogTemp, Warning, TEXT("%s is releasing the lock..."),
  73.             *GetStatId().GetName().ToString()
  74.         ); 
  75.     }  
  76.    
  77. }
  78.  
RAW Paste Data