The Storage module manages data persistence, profile management, and export functionality for the Game Macro system.
| English Version | 中文版本 |
The Storage module provides:
The storage system is organized into specialized components:
Main storage management and coordination system.
Data export and external format conversion.
Data model definitions and structures.
Profile management and file system operations.
Manages game profiles including loading, saving, and validation.
Profile := {
Id: "profile-001",
Name: "Warrior Rotation",
Version: "1.0.0",
Game: "World of Warcraft",
Class: "Warrior",
Created: "2024-01-01T00:00:00Z",
Modified: "2024-01-02T12:00:00Z",
Data: {
Skills: [...],
Buffs: [...],
Rules: [...],
Rotation: {...},
Points: [...],
General: {...}
}
}
Provides atomic file operations and path management.
FileSystem := {
ProfilesDir: "profiles",
ExportDir: "exports",
BackupDir: "backups",
TempDir: "temp"
}
Manages data export to external formats.
ExportConfig := {
Format: "JSON",
IncludeSensitiveData: false,
Compress: true,
Timestamp: true
}
Defines data structures and validation schemas.
Model := {
Name: "Skill",
Fields: {
Id: {Type: "Integer", Required: true},
Name: {Type: "String", Required: true},
Key: {Type: "String", Required: true},
CooldownMs: {Type: "Integer", Default: 0}
},
Validation: Func("ValidateSkill")
}
Initializes the storage system.
Parameters: None
Returns: Boolean indicating success
Loads a profile by ID.
Parameters:
profileId (String): Profile identifierReturns: Loaded profile data
Saves profile data.
Parameters:
profileData (Map): Profile data to saveReturns: Boolean indicating success
Deletes a profile.
Parameters:
profileId (String): Profile identifierReturns: Boolean indicating success
Lists all available profiles.
Parameters: None
Returns: Array of profile information
Creates a new profile.
Parameters:
profileConfig (Map): Profile configurationReturns: Created profile ID
Duplicates an existing profile.
Parameters:
sourceId (String): Source profile IDnewName (String): New profile nameReturns: New profile ID
Validates profile data.
Parameters:
profileData (Map): Profile data to validateReturns: Validation result
Exports a profile to external format.
Parameters:
profileId (String): Profile identifierexportConfig (Map): Export configurationReturns: Export file path
Imports a profile from external file.
Parameters:
filePath (String): Import file pathimportConfig (Map): Import configurationReturns: Imported profile ID
Gets available export formats.
Parameters: None
Returns: Array of export formats
Creates a backup of a profile.
Parameters:
profileId (String): Profile identifierReturns: Backup file path
Restores a profile from backup.
Parameters:
backupPath (String): Backup file pathReturns: Restored profile ID
Gets the file path for a profile.
Parameters:
profileId (String): Profile identifierReturns: Profile file path
; Initialize storage system
if (!Storage_Init()) {
Logger_Error("Storage", "Failed to initialize storage system")
ExitApp(1)
}
; List available profiles
profiles := Storage_ListProfiles()
for profile in profiles {
Logger_Info("Storage", "Available profile", Map("name", profile["Name"], "id", profile["Id"]))
}
; Load a profile
profileData := Storage_LoadProfile("warrior-rotation")
if (profileData) {
Logger_Info("Storage", "Profile loaded successfully", Map("name", profileData["Name"]))
}
; Create a new profile
newProfile := {
Name: "Mage Rotation",
Game: "World of Warcraft",
Class: "Mage",
Data: {
Skills: [
{
Id: 1,
Name: "Fireball",
Key: "1",
CooldownMs: 2000
}
],
Rotation: {
Type: "Priority",
Skills: [1]
}
}
}
profileId := Storage_CreateProfile(newProfile)
Logger_Info("Storage", "Profile created", Map("id", profileId))
; Save current profile data
if (Storage_SaveProfile(App["CurrentProfile"])) {
Logger_Info("Storage", "Profile saved successfully")
}
; Export profile to JSON
exportConfig := {
Format: "JSON",
IncludeSensitiveData: false,
Compress: true
}
exportPath := Storage_ExportProfile("warrior-rotation", exportConfig)
Logger_Info("Storage", "Profile exported", Map("path", exportPath))
; Import profile from file
importConfig := {
OverwriteExisting: false,
ValidateData: true
}
importedId := Storage_ImportProfile("C:\backups\warrior-backup.json", importConfig)
Logger_Info("Storage", "Profile imported", Map("id", importedId))
; Create backup
backupPath := Storage_CreateBackup("warrior-rotation")
Logger_Info("Storage", "Backup created", Map("path", backupPath))
; Restore from backup
restoredId := Storage_RestoreBackup("C:\backups\warrior-rotation-backup.json")
Logger_Info("Storage", "Profile restored", Map("id", restoredId))
; Validate profile data before saving
validationResult := Storage_ValidateProfile(profileData)
if (!validationResult["IsValid"]) {
Logger_Error("Storage", "Profile validation failed", validationResult["Errors"])
return false
}
; Save only if validation passes
Storage_SaveProfile(profileData)
Storage settings are configured in the main application:
App["StorageConfig"] := {
ProfilesDir: "profiles",
ExportDir: "exports",
BackupDir: "backups",
AutoSave: true,
AutoSaveInterval: 300000, ; 5 minutes
MaxBackups: 10,
Compression: true
}
Profile data follows a standardized structure:
profile["Data"] := {
Skills: [
{
Id: 1,
Name: "Skill Name",
Key: "1",
X: 100,
Y: 200,
Color: "0xFF0000",
CooldownMs: 2000
}
],
Buffs: [...],
Rules: [...],
Rotation: {
Type: "Priority",
Skills: [1, 2, 3],
Conditions: [...]
},
Points: [...],
General: {
GameWindow: "World of Warcraft",
PollingInterval: 100
}
}
The storage module includes comprehensive error handling:
The module provides debugging capabilities:
; Enable storage debugging
Storage_EnableDebug()
; Get debug information
debugInfo := Storage_GetDebugInfo()
All storage operations are logged for troubleshooting: