01. Introduction to configuration table management tools
Station B address: Portal
1. Introduction
MxConfig is a tool to automatically manage our configuration table. It is a sub-module of the MxFramework framework . Commonly used configuration table formats are Json format, Xml format, CSV format, etc. Manually writing these formats will have a series of problems such as error-prone, difficult to expand, heavy workload, and difficult to maintain. The MxConfig tool exists to solve these problems. We can write our configuration table through Excel without writing any scripts. The configuration table is parsed and loaded with one click. The configuration table will eventually be converted into an encrypted format. , Through the template custom analysis script, a series of repetitive tasks such as parsing, loading and expansion are handed over to the tool to automatically generate, which greatly saves our development costs.
2. Download the source code
1. Go to the GitHub source code address: https://github.com/yongliangchen/MXFramework to download
3. Project structure
1. Source code storage path
ImportPlugins/MXFramework**/Core/Config
2. Template storage path
ImportPlugins/MXFramework**/Resources/Template/Config
3. Sample project storage path
Example/02_Config
4. The original file storage path of the configuration table
Res/Csv/IOCsv ( configuration table for dynamic loading mode)
Res/Csv/ResourcesCsv (configuration table of internal loading method)
5. Automatically generate configuration table storage path
StreamingAssets/Config/ Configuration table name ( automatically generate configuration table data for dynamic loading)
Resources /Config/ Configuration table name (automatically generate configuration table data for internal loading mode)
6. Storage path of encryption algorithm
ImportPlugins/MXFramework**/Core/Util/StringEncrypt.cs
7. Automatically generated parsing and loading code path
Scripts /AutoGenerate/ Configuration table name.cs
Four, loading method
1. Dynamic loading rules
All files stored in the Res/Csv/IOCsv/ configuration table name.csv path need to be dynamically loaded. Generally, the configuration tables placed in this directory are used for hot update. The automatically generated data files are stored in StreamingAssets/Config / Configuration table name.txt path. (Loaded by the following code)
StreamReader streamReader = null;
if (File.Exists(DataPath())) streamReader = File.OpenText(DataPath());
The StreamingAssets directory cannot perform io operations on Android devices , so we need to copy the data to the persistentDataPath directory (for details, please refer to Example/02_Config/TestIOCsvConfig.cs)
2. Internal loading rules
All the files stored in the Res/Csv/ResourcesCsv/configuration table name.csv path are loaded internally, generally storing configuration files that do not need to be changed, and the automatically generated data files are stored in the Resources/Config/ configuration table name.txt path . (Loaded by the following code)
TextAsset textAsset = Resources.Load<TextAsset>(DataPath());
(For details, please refer to Example/02_Config/TestResourcesCsvConfig.cs)
Five, encryption algorithm
1. XOR encryption algorithm
XOR is a logical analysis of the two operand type, symbol XOR or EOR. Different from general logic or OR, when the two values are the same, it is no, but when the values are different, it is true. XOR cipher (Simple the XOR cipher) iscryptographyin a simple encryption algorithm, refers to the information to achieve the exclusive-OR operation for encryption and decryption purposes. According to this logic, each character of the text serial can be encrypted by performing a bitwise XOR operation with a given key. If you want to decrypt, you only need to perform a bitwise XOR operation again between the encrypted result and the key. (Fordetails, please go here)
2. Encryption
public static string EncryptDES(string encryptString, string key = "45131929"){}
The number of keys is 8 digits and the default is "45131929"
3. Decrypt
public static string DecryptDES(string decryptString, string key = "45131929"){}
The number of keys is 8 digits and the default is "45131929"
6. How to use
1. Configuration table format (take TestIOCsvConfig.csv as an example)
2. Write the configuration table (take TestIOCsvConfig.csv as an example)
First, we copy the template file in the Res/Csv/IOCsv/ directory and name it "TestIOCsvConfig.csv", then right-click Reveal in Finder
Double-click the "TestIOCsvConfig.csv" file to open the file with Excel software. The first line writes the data type/name, and the second line after the specific data (the array is separated by semicolons) is written and the file is saved by Control+S .
Or save as CSV UTF-8 (comma separated) (.CSV)
3. Automatically generate configuration table and analysis code
Click the MXFramework/Config/Generate Script button
(For the generated configuration table path and code path, please refer to 2. Project Structure)
Seven, automatically generated code API
1. Data type (take TestIOCsvConfig.csv as an example)
2. Parse the script (take TestIOCsvConfig.csv as an example)
public uint TypeID()//获取类型 ID
public string DataPath()//获取数存放路径
public void Load()//加载数据
public TestIOCsvConfigData GetDataByKey(string key)//通过 key 或 者一条数据,这里指的是 ID,每个数据的第一项
public int GetCount()//获取数据数量
public List <TestIOCsvConfigData> GetAllData()//获取所有的数据
8. Load and parse configuration table
1. Load the configuration table
private TestIOCsvConfigDatabase m_Database;
m_Database = new TestIOCsvConfigDatabase();
m_Database.Load();
2. Analyze the configuration table (take TestIOCsvConfig.csv as an example)
Nine, data collation
MxFramework source code: https://github.com/yongliangchen/MXFramework
QQ exchange group: 1079467433