Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] 保留可移动存储设备中的游戏安装路径 #1081

Open
2 tasks done
Scighost opened this issue Sep 7, 2024 · 3 comments
Open
2 tasks done

[Feature] 保留可移动存储设备中的游戏安装路径 #1081

Scighost opened this issue Sep 7, 2024 · 3 comments
Labels
Area: Launcher enhancement New feature or request

Comments

@Scighost
Copy link
Owner

Scighost commented Sep 7, 2024

Checklist

  • I have already read docs/Tips.md, but my feature is not implemented.
  • My suggested feature was not mentioned by others, and it is not a duplicate feature.

Summary

在当前的逻辑中,如果游戏安装路径不存在,则会在检测后恢复到未设定的状态。有玩家把游戏安装在移动硬盘中,当移动硬盘未连接时,Starward 会自动重置对应游戏的安装路径,下次启动时需要重新定位。这个操作对于这部分玩家很不友好。

#1075

Solution or Design

  • 定位或安装游戏时检测目标路径是否是可移动存储设备,并保存此信息
  • 检测到不存在的游戏路径,若为可移动存储设备,在首页显示明显提醒
@Scighost
Copy link
Owner Author

Scighost commented Sep 7, 2024

在我的测试中,移动固态硬盘无法被识别为可移动存储设备,DriveInfo.DriveType 的方案不可行。

在 Windows 系统中,当你通过 GetDriveType API 获取硬盘类型时,返回的值表示驱动器类型的类别,而不是物理连接的类型。Fixed 通常表示这是一个固定驱动器(本地硬盘),而 Removable 则表示它是一个可移动驱动器(如 U 盘)。然而,在某些情况下,即使设备是通过 USB 连接的 SSD 或硬盘,它仍然可能被识别为 Fixed,这是由于 Windows 系统对某些设备类型的识别方式不同所致。

改用其他的方法,考虑通过存储设备是否是 USB 连接,判断是否为可移动存储。

HANDLE hDevice = CreateFile(LR"(\\.\C:)", 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE) {
	printf("无法打开设备,错误代码: %lu\n", GetLastError());
	return;
}

STORAGE_PROPERTY_QUERY query;
memset(&query, 0, sizeof(STORAGE_PROPERTY_QUERY));
query.PropertyId = StorageDeviceProperty;
query.QueryType = PropertyStandardQuery;

STORAGE_DEVICE_DESCRIPTOR desc;
DWORD bytesReturned;

if (DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &desc, sizeof(desc), &bytesReturned, NULL)) {
	if (desc.BusType == BusTypeUsb) {
		printf("设备连接在 USB 总线上\n");
	}
	else {
		printf("设备不在 USB 总线上\n");
	}
}
else {
	printf("DeviceIoControl 失败,错误代码: %lu\n", GetLastError());
}

CloseHandle(hDevice);

@Scighost
Copy link
Owner Author

Scighost commented Sep 7, 2024

检测设备连接后自动刷新状态的功能,后续版本再加入。

@rihalvnium76
Copy link

直接加个开关,无效路径不重置

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Launcher enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants