installerbuilder/tasks/task10-Windows平台适配器.md

128 lines
4.1 KiB
Markdown
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.

# 任务10Windows平台适配器
## 任务描述
实现Windows平台的适配器处理Windows特定的操作和逻辑。Windows平台适配器将实现平台适配接口为Windows平台提供特定的功能实现确保安装包构建过程能够正确处理Windows平台的特性。
## 实现步骤
1. 创建Windows平台适配器
- 在`internal/platform/windows`包中创建`adapter.go`文件
- 定义WindowsAdapter结构体实现PlatformAdapter接口
```go
type WindowsAdapter struct {
info platform.PlatformInfo
logger log.Logger
resource resource.ResourceManager
arch string
}
```
- 实现构造函数:
```go
func NewWindowsAdapter(arch string, logger log.Logger, resource resource.ResourceManager) *WindowsAdapter {
return &WindowsAdapter{
info: platform.PlatformInfo{
Name: platform.PlatformWindows,
Arch: arch,
DefaultInstallDir: "C:\\Program Files",
PathSeparator: "\\",
ExecutableExt: ".exe",
DynamicLibExt: ".dll",
StaticLibExt: ".lib",
ScriptExt: map[string]string{
"batch": ".bat",
"powershell": ".ps1",
},
},
logger: logger,
resource: resource,
arch: arch,
}
}
```
2. 实现平台信息方法:
- 实现GetPlatformInfo方法返回Windows平台信息
- 根据架构调整默认安装目录如x86程序使用"Program Files (x86)"
- 添加Windows版本检测
3. 实现环境准备和清理:
- 实现PrepareEnvironment方法准备Windows构建环境
- 实现CleanupEnvironment方法清理Windows构建环境
- 处理Windows特定的环境设置
4. 实现路径处理:
- 实现NormalizePath方法规范化Windows路径
- 实现IsPathAbsolute方法判断Windows绝对路径
- 实现JoinPaths方法连接Windows路径
- 处理Windows路径长度限制
5. 实现文件系统操作:
- 实现GetTempDir方法获取Windows临时目录
- 实现SetFilePermissions方法设置Windows文件权限
- 处理Windows文件系统特性如文件锁定
6. 实现环境变量处理:
- 实现GetOSEnv方法获取Windows环境变量
- 处理Windows环境变量的大小写不敏感特性
- 支持系统和用户级环境变量
7. 实现Windows特定功能
- 添加注册表操作方法
- 添加服务操作方法
- 添加快捷方式创建方法
- 添加UAC提升权限检查
## 单元测试要求
1. 测试平台信息:
- 验证Windows平台信息的正确性
- 测试不同架构的平台信息
2. 测试环境准备和清理:
- 验证环境准备方法
- 测试环境清理方法
- 测试异常情况处理
3. 测试路径处理:
- 验证路径规范化
- 测试绝对路径判断
- 测试路径连接
- 测试长路径处理
4. 测试文件系统操作:
- 验证临时目录获取
- 测试文件权限设置
- 测试文件锁定处理
5. 测试环境变量处理:
- 验证环境变量获取
- 测试大小写不敏感特性
- 测试系统和用户级环境变量
6. 测试Windows特定功能
- 验证注册表操作
- 测试服务操作
- 测试快捷方式创建
- 测试UAC权限检查
## 依赖关系
- 依赖任务01项目初始化
- 依赖任务02日志系统实现
- 依赖任务03错误处理框架
- 依赖任务04资源管理器实现
- 依赖任务09平台适配接口定义
- 被任务12MSI包构建器和任务15ZIP包构建器依赖
## 完成标准
1. WindowsAdapter实现了所有PlatformAdapter接口方法
2. Windows平台信息正确定义
3. 环境准备和清理功能正常工作
4. 路径处理功能正常工作
5. 文件系统操作功能正常工作
6. 环境变量处理功能正常工作
7. Windows特定功能正常工作
8. 所有单元测试通过
9. 代码符合项目的Go语言开发规范
10. 适配器能够处理Windows平台的特性和限制