Skip to content

Commit

Permalink
Merge pull request #1 from g0415shenw/main
Browse files Browse the repository at this point in the history
提交基础版本
  • Loading branch information
g0415shenw authored Aug 30, 2022
2 parents f9f4d71 + 6ca0343 commit f704dce
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 1 deletion.
Binary file added Images/ConfigFile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/GetConfig.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Images/SetConfig.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions InConfig.uplugin
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.0",
"FriendlyName": "InConfig",
"Description": "",
"Category": "Other",
"CreatedBy": "",
"CreatedByURL": "",
"DocsURL": "",
"MarketplaceURL": "",
"SupportURL": "",
"CanContainContent": true,
"IsBetaVersion": false,
"IsExperimentalVersion": false,
"Installed": false,
"Modules": [
{
"Name": "InConfig",
"Type": "Runtime",
"LoadingPhase": "PreLoadingScreen"
}
]
}
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# InConfig
# InConfig
本插件旨在简化配置文件的读写。通过本插件进行读写配置文件,可以适用于编辑器和运行时模型。

# 使用方法
## 设置配置文件
目前支持字符串和整数的配置文件读写。通过调用蓝图方式,可以实现自动生成配置文件,并且生成的配置文件在打包的时候,会自动被拷贝到安装程序中。
![SetConfig](./Images/SetConfig.jpg)
生成的配置文件如下:
![ConfigFile](./Images/ConfigFile.jpg)

## 读取配置文件
目前仅仅支持字符串和整数的配置文件读写。
![GetConfig](./Images/GetConfig.jpg)
Binary file added Resources/Icon128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
53 changes: 53 additions & 0 deletions Source/InConfig/InConfig.Build.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Some copyright should be here...

using UnrealBuildTool;

public class InConfig : ModuleRules
{
public InConfig(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs;

PublicIncludePaths.AddRange(
new string[] {
// ... add public include paths required here ...
}
);


PrivateIncludePaths.AddRange(
new string[] {
// ... add other private include paths required here ...
}
);


PublicDependencyModuleNames.AddRange(
new string[]
{
"Core",
// ... add other public dependencies that you statically link with here ...
}
);


PrivateDependencyModuleNames.AddRange(
new string[]
{
"CoreUObject",
"Engine",
"Slate",
"SlateCore",
// ... add private dependencies that you statically link with here ...
}
);


DynamicallyLoadedModuleNames.AddRange(
new string[]
{
// ... add any modules that your module loads dynamically here ...
}
);
}
}
22 changes: 22 additions & 0 deletions Source/InConfig/Private/InConfig.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#include "InConfig.h"

#define LOCTEXT_NAMESPACE "FInConfigModule"

void FInConfigModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module

}

void FInConfigModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
// we call this function before unloading the module.

}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FInConfigModule, InConfig)
63 changes: 63 additions & 0 deletions Source/InConfig/Private/InConfigBPLibrary.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#include "InConfigBPLibrary.h"
#include "InConfig.h"
#include "Misc/Paths.h"
#include "Misc/App.h"
#include "HAL/FileManager.h"

FString UInConfigBPLibrary::GetConfigPath()
{
FString ProjectPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
FString ProjectName = FApp::GetProjectName();
FString ConfigPath = ProjectPath + "Config/" + ProjectName + ".ini";
return ConfigPath;
}
void UInConfigBPLibrary::CheckAndCreateConfig()
{
FString ProjectPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir());
FString ProjectName = FApp::GetProjectName();
FString ConfigPath = GetConfigPath();
FString DefaultGamePath = ProjectPath + "Config/" + "DefaultGame.ini";

if (true == FPaths::FileExists(ConfigPath))
{
return;
}
auto file = IFileManager::Get().CreateFileWriter(*ConfigPath);
if (nullptr == file)
{
return;
}
file->Close();

FString fileName = ProjectName + "/" + "Config/" + ProjectName + ".ini";
GConfig->SetString(TEXT("Staging"), TEXT("+WhitelistConfigFiles"), *fileName, *DefaultGamePath);
}

bool UInConfigBPLibrary::GetConfigString(FString Section, FString Key, FString& value)
{
FString ConfigPath = GetConfigPath();
return GConfig->GetString(*Section, *Key, value, ConfigPath);
}

void UInConfigBPLibrary::SetConfigString(FString Section, FString Key, FString value)
{
CheckAndCreateConfig();
FString ConfigPath = GetConfigPath();
GConfig->SetString(*Section, *Key, *value, ConfigPath);
}

bool UInConfigBPLibrary::GetConfigInt(FString Section, FString Key, int32& value)
{
FString ConfigPath = GetConfigPath();
return GConfig->GetInt(*Section, *Key, value, ConfigPath);
}


void UInConfigBPLibrary::SetConfigInt(FString Section, FString Key, int32 value)
{
CheckAndCreateConfig();
FString ConfigPath = GetConfigPath();
GConfig->SetInt(*Section, *Key, value, ConfigPath);
}
14 changes: 14 additions & 0 deletions Source/InConfig/Public/InConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "Modules/ModuleManager.h"

class FInConfigModule : public IModuleInterface
{
public:

/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
};
29 changes: 29 additions & 0 deletions Source/InConfig/Public/InConfigBPLibrary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include "Kismet/BlueprintFunctionLibrary.h"
#include "InConfigBPLibrary.generated.h"


UCLASS()
class UInConfigBPLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

private:
static void CheckAndCreateConfig();
static FString GetConfigPath();
public:
UFUNCTION(BlueprintCallable, Category = "InConfig")
static bool GetConfigString(FString Section, FString Key, FString& value);

UFUNCTION(BlueprintCallable, Category = "InConfig")
static void SetConfigString(FString Section, FString Key, FString value);

UFUNCTION(BlueprintCallable, Category = "InConfig")
static bool GetConfigInt(FString Section, FString Key, int32& value);

UFUNCTION(BlueprintCallable, Category = "InConfig")
static void SetConfigInt(FString Section, FString Key, int32 value);
};

0 comments on commit f704dce

Please sign in to comment.