Files
4566704 63d0a0caf8 feat(cafegame): 自 go-hua 迁入网咖游戏识别与运行记录框架
- 游戏来源常量/按目录特征识别(云更新/网维大师/易乐游)/RunAppRecord 上报框架
- 网吧业务专用包, 附测试、examples/cafegame 例程与包 README
2026-09-20 12:37:10 +08:00

44 lines
1.6 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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)
}