86 lines
1.7 KiB
C++
86 lines
1.7 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
#include "ResComUserStoreLocalData.h"
|
|
#include "../CPPFunctionLibrary.h"
|
|
|
|
UResComUserStoreLocalData::UResComUserStoreLocalData()
|
|
{
|
|
}
|
|
|
|
UResComUserStoreLocalData::~UResComUserStoreLocalData()
|
|
{
|
|
}
|
|
|
|
void UResComUserStoreLocalData::SetWorkingDirectory(FString path)
|
|
{
|
|
WorkingDirectoryPath = path;
|
|
}
|
|
|
|
FStruct_User UResComUserStoreLocalData::GetEmptyUser()
|
|
{
|
|
return FStruct_User();
|
|
}
|
|
|
|
FStruct_User UResComUserStoreLocalData::GetUser(FString phone)
|
|
{
|
|
FString FileData;
|
|
if (!FPaths::FileExists(WorkingDirectoryPath))
|
|
return GetEmptyUser();
|
|
|
|
FFileHelper::LoadFileToString(WorkingDirectoryPath, *FileData);
|
|
|
|
if (!FileData.Len())
|
|
return GetEmptyUser();
|
|
|
|
if (!FileData.Contains(phone))
|
|
return GetEmptyUser();
|
|
|
|
|
|
int32 startIndex = FileData.Find(phone);
|
|
int32 endIndex = FileData.Find(FString("\n"), ESearchCase::IgnoreCase, ESearchDir::FromStart, startIndex);
|
|
|
|
return GetUserFromString(FileData.Mid(startIndex, endIndex - startIndex));
|
|
|
|
}
|
|
|
|
void UResComUserStoreLocalData::AddUser(FString Phone, FString Name, FString Email, TArray<FString> FavoriteIDs)
|
|
{
|
|
|
|
}
|
|
|
|
FStruct_User UResComUserStoreLocalData::GetUserFromString(FString string)
|
|
{
|
|
int32 commaNum = 0;
|
|
FStruct_User user;
|
|
FString flatIndex;
|
|
|
|
for (int i = 0; i < string.Len(); ++i)
|
|
{
|
|
if (string[i] == ',')
|
|
{
|
|
if (commaNum > 2)
|
|
{
|
|
user.favoriteFlatsIndices.Add(FCString::Atoi(*flatIndex));
|
|
flatIndex.Empty();
|
|
}
|
|
++commaNum;
|
|
}
|
|
if (string[i] != ',')
|
|
switch (commaNum)
|
|
{
|
|
case 0:
|
|
user.phone += string[i];
|
|
break;
|
|
case 1:
|
|
user.name += string[i];
|
|
break;
|
|
case 2:
|
|
user.email += string[i];
|
|
break;
|
|
default:
|
|
flatIndex += string[i];
|
|
break;
|
|
}
|
|
}
|
|
return user;
|
|
} |