├── .gitignore ├── Images ├── ConfigFile.jpg ├── GetConfig.jpg └── SetConfig.jpg ├── InConfig.uplugin ├── LICENSE ├── README.md ├── Resources └── Icon128.png └── Source └── InConfig ├── InConfig.Build.cs ├── Private ├── InConfig.cpp └── InConfigBPLibrary.cpp └── Public ├── InConfig.h └── InConfigBPLibrary.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Visual Studio 2015 user specific files 2 | .vs/ 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | 22 | # Compiled Static libraries 23 | *.lai 24 | *.la 25 | *.a 26 | *.lib 27 | 28 | # Executables 29 | *.exe 30 | *.out 31 | *.app 32 | *.ipa 33 | 34 | # These project files can be generated by the engine 35 | *.xcodeproj 36 | *.xcworkspace 37 | *.sln 38 | *.suo 39 | *.opensdf 40 | *.sdf 41 | *.VC.db 42 | *.VC.opendb 43 | 44 | # Precompiled Assets 45 | SourceArt/**/*.png 46 | SourceArt/**/*.tga 47 | 48 | # Binary Files 49 | Binaries/* 50 | Plugins/*/Binaries/* 51 | 52 | # Builds 53 | Build/* 54 | 55 | # Whitelist PakBlacklist-.txt files 56 | !Build/*/ 57 | Build/*/** 58 | !Build/*/PakBlacklist*.txt 59 | 60 | # Don't ignore icon files in Build 61 | !Build/**/*.ico 62 | 63 | # Built data for maps 64 | *_BuiltData.uasset 65 | 66 | # Configuration files generated by the Editor 67 | Saved/* 68 | 69 | # Compiled source files for the engine to use 70 | Intermediate/* 71 | Plugins/*/Intermediate/* 72 | 73 | # Cache files for the editor to use 74 | DerivedDataCache/* 75 | -------------------------------------------------------------------------------- /Images/ConfigFile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inveta/InConfig/7330c95582f4ba3ed3de9616ff3f08a0aad01138/Images/ConfigFile.jpg -------------------------------------------------------------------------------- /Images/GetConfig.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inveta/InConfig/7330c95582f4ba3ed3de9616ff3f08a0aad01138/Images/GetConfig.jpg -------------------------------------------------------------------------------- /Images/SetConfig.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inveta/InConfig/7330c95582f4ba3ed3de9616ff3f08a0aad01138/Images/SetConfig.jpg -------------------------------------------------------------------------------- /InConfig.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0", 5 | "FriendlyName": "InConfig", 6 | "Description": "", 7 | "Category": "Other", 8 | "CreatedBy": "", 9 | "CreatedByURL": "", 10 | "DocsURL": "", 11 | "MarketplaceURL": "", 12 | "SupportURL": "", 13 | "CanContainContent": true, 14 | "IsBetaVersion": false, 15 | "IsExperimentalVersion": false, 16 | "Installed": false, 17 | "Modules": [ 18 | { 19 | "Name": "InConfig", 20 | "Type": "Runtime", 21 | "LoadingPhase": "PreLoadingScreen" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 inveta 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InConfig 2 | 本插件旨在简化配置文件的读写。通过本插件进行读写配置文件,可以适用于编辑器和运行时模型。 3 | 4 | # 使用方法 5 | ## 设置配置文件 6 | 目前支持字符串和整数的配置文件读写。通过调用蓝图方式,可以实现自动生成配置文件,并且生成的配置文件在打包的时候,会自动被拷贝到安装程序中。 7 | ![SetConfig](./Images/SetConfig.jpg) 8 | 生成的配置文件如下: 9 | ![ConfigFile](./Images/ConfigFile.jpg) 10 | 11 | ## 读取配置文件 12 | 目前仅仅支持字符串和整数的配置文件读写。 13 | ![GetConfig](./Images/GetConfig.jpg) 14 | -------------------------------------------------------------------------------- /Resources/Icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inveta/InConfig/7330c95582f4ba3ed3de9616ff3f08a0aad01138/Resources/Icon128.png -------------------------------------------------------------------------------- /Source/InConfig/InConfig.Build.cs: -------------------------------------------------------------------------------- 1 | // Some copyright should be here... 2 | 3 | using UnrealBuildTool; 4 | using System; 5 | using System.IO; 6 | 7 | public class InConfig : ModuleRules 8 | { 9 | public InConfig(ReadOnlyTargetRules Target) : base(Target) 10 | { 11 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 12 | 13 | PublicIncludePaths.AddRange( 14 | new string[] { 15 | // ... add public include paths required here ... 16 | } 17 | ); 18 | 19 | 20 | PrivateIncludePaths.AddRange( 21 | new string[] { 22 | // ... add other private include paths required here ... 23 | } 24 | ); 25 | 26 | 27 | PublicDependencyModuleNames.AddRange( 28 | new string[] 29 | { 30 | "Core", 31 | // ... add other public dependencies that you statically link with here ... 32 | } 33 | ); 34 | 35 | 36 | PrivateDependencyModuleNames.AddRange( 37 | new string[] 38 | { 39 | "CoreUObject", 40 | "Engine", 41 | "Slate", 42 | "SlateCore", 43 | // ... add private dependencies that you statically link with here ... 44 | } 45 | ); 46 | 47 | 48 | DynamicallyLoadedModuleNames.AddRange( 49 | new string[] 50 | { 51 | // ... add any modules that your module loads dynamically here ... 52 | } 53 | ); 54 | 55 | string pluginPath = PluginDirectory; 56 | string[] dirNameArray = pluginPath.Split("\\"); 57 | string projectName = dirNameArray[dirNameArray.Length - 3]; 58 | 59 | RuntimeDependencies.Add(Path.Combine(PluginDirectory, "../../Config", projectName + ".ini")); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Source/InConfig/Private/InConfig.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "InConfig.h" 4 | 5 | #define LOCTEXT_NAMESPACE "FInConfigModule" 6 | 7 | void FInConfigModule::StartupModule() 8 | { 9 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 10 | 11 | } 12 | 13 | void FInConfigModule::ShutdownModule() 14 | { 15 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 16 | // we call this function before unloading the module. 17 | 18 | } 19 | 20 | #undef LOCTEXT_NAMESPACE 21 | 22 | IMPLEMENT_MODULE(FInConfigModule, InConfig) -------------------------------------------------------------------------------- /Source/InConfig/Private/InConfigBPLibrary.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "InConfigBPLibrary.h" 4 | #include "InConfig.h" 5 | #include "Misc/Paths.h" 6 | #include "Misc/App.h" 7 | #include "HAL/FileManager.h" 8 | 9 | FString UInConfigBPLibrary::GetConfigPath() 10 | { 11 | FString ProjectPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir()); 12 | FString ProjectName = FApp::GetProjectName(); 13 | FString ConfigPath = ProjectPath + "Config/" + ProjectName + ".ini"; 14 | return ConfigPath; 15 | } 16 | void UInConfigBPLibrary::CheckAndCreateConfig() 17 | { 18 | FString ProjectPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir()); 19 | FString ProjectName = FApp::GetProjectName(); 20 | FString ConfigPath = GetConfigPath(); 21 | FString DefaultGamePath = ProjectPath + "Config/" + "DefaultGame.ini"; 22 | 23 | if (true == FPaths::FileExists(ConfigPath)) 24 | { 25 | return; 26 | } 27 | auto file = IFileManager::Get().CreateFileWriter(*ConfigPath); 28 | if (nullptr == file) 29 | { 30 | return; 31 | } 32 | file->Close(); 33 | 34 | FString fileName = ProjectName + "/" + "Config/" + ProjectName + ".ini"; 35 | GConfig->SetString(TEXT("Staging"), TEXT("+BlacklistConfigFiles"), *fileName, *DefaultGamePath); 36 | } 37 | 38 | bool UInConfigBPLibrary::GetConfigString(FString Section, FString Key, FString& value) 39 | { 40 | FString ConfigPath = GetConfigPath(); 41 | return GConfig->GetString(*Section, *Key, value, ConfigPath); 42 | } 43 | 44 | void UInConfigBPLibrary::SetConfigString(FString Section, FString Key, FString value) 45 | { 46 | CheckAndCreateConfig(); 47 | FString ConfigPath = GetConfigPath(); 48 | GConfig->SetString(*Section, *Key, *value, ConfigPath); 49 | } 50 | 51 | bool UInConfigBPLibrary::GetConfigInt(FString Section, FString Key, int32& value) 52 | { 53 | FString ConfigPath = GetConfigPath(); 54 | return GConfig->GetInt(*Section, *Key, value, ConfigPath); 55 | } 56 | 57 | 58 | void UInConfigBPLibrary::SetConfigInt(FString Section, FString Key, int32 value) 59 | { 60 | CheckAndCreateConfig(); 61 | FString ConfigPath = GetConfigPath(); 62 | GConfig->SetInt(*Section, *Key, value, ConfigPath); 63 | } -------------------------------------------------------------------------------- /Source/InConfig/Public/InConfig.h: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "Modules/ModuleManager.h" 6 | 7 | class FInConfigModule : public IModuleInterface 8 | { 9 | public: 10 | 11 | /** IModuleInterface implementation */ 12 | virtual void StartupModule() override; 13 | virtual void ShutdownModule() override; 14 | }; 15 | -------------------------------------------------------------------------------- /Source/InConfig/Public/InConfigBPLibrary.h: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "Kismet/BlueprintFunctionLibrary.h" 6 | #include "InConfigBPLibrary.generated.h" 7 | 8 | 9 | UCLASS() 10 | class UInConfigBPLibrary : public UBlueprintFunctionLibrary 11 | { 12 | GENERATED_BODY() 13 | 14 | private: 15 | static void CheckAndCreateConfig(); 16 | static FString GetConfigPath(); 17 | public: 18 | UFUNCTION(BlueprintCallable, Category = "InConfig") 19 | static bool GetConfigString(FString Section, FString Key, FString& value); 20 | 21 | UFUNCTION(BlueprintCallable, Category = "InConfig") 22 | static void SetConfigString(FString Section, FString Key, FString value); 23 | 24 | UFUNCTION(BlueprintCallable, Category = "InConfig") 25 | static bool GetConfigInt(FString Section, FString Key, int32& value); 26 | 27 | UFUNCTION(BlueprintCallable, Category = "InConfig") 28 | static void SetConfigInt(FString Section, FString Key, int32 value); 29 | }; 30 | --------------------------------------------------------------------------------