// cafegame 包示例:网咖游戏识别(按各游戏平台目录特征判断游戏来源与 ID) package main import ( "fmt" "os" "path/filepath" "git.zeroonesoft.cn/golib/zogo/cafegame" ) func main() { // 游戏来源常量与名称 for _, id := range cafegame.GetSourceAll() { fmt.Printf("来源 %2d: %s\n", id, cafegame.SourceToName(id)) } // 构造一个模拟的"云更新"游戏目录,演示目录识别 // 云更新特征:目录下有 gamepatch/gconfig.ini,且有数字命名的 .ico 图标(ID≥40000) root := filepath.Join(os.TempDir(), "go-hua-cafegame-demo", "40001示例游戏") _ = os.MkdirAll(filepath.Join(root, "gamepatch"), 0755) _ = os.WriteFile(filepath.Join(root, "gamepatch", "gconfig.ini"), nil, 0644) _ = os.WriteFile(filepath.Join(root, "40001.ico"), nil, 0644) defer os.RemoveAll(filepath.Dir(root)) ok, info, err := cafegame.IsGameDirByYGX(root) fmt.Println("是否云更新游戏目录:", ok, "错误:", err) if ok { fmt.Printf("识别结果: Id=%d Name=%s Source=%d(%s)\n", info.AppId, info.AppName, info.AppSource, cafegame.SourceToName(info.AppSource)) } // 实际使用中扫描游戏盘根目录,自动识别所有游戏: // entries, _ := os.ReadDir("D:\\") // for _, e := range entries { // if info, err := cafegame.GetGameInfoByDir(filepath.Join("D:\\", e.Name())); err == nil && (info.AppId > 0 || info.AppGuid != "") { // fmt.Printf("%+v\n", info) // } // } // // 游戏运行记录/监控入口(Windows): // cafegame.RunAppRecord(recordCallback, countCallback, eventCallback, sourceList, reportInterval) }