Очищать каталоги Android при запуске и проверять маркер DATA

This commit is contained in:
Paravis committed 2026-11-14 19:08:29 +03:00
1 parent a6690504eb
commit c6cf1d7fbf
5 files changed
+202

No files matched your search

+1
View File
@@ -11,6 +11,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(ChangeBootLoader WIN32
src/main.cpp
src/boot.cpp
src/cleanup.cpp
src/util.cpp
src/app.rc
)
+5
View File
@@ -35,6 +35,11 @@ build\Release\Change_BootLoader.exe
подсветить установленный загрузчик.
- При запуске читает `bootstate.txt` и подсвечивает текущий Legacy- и
UEFI-загрузчик тем же стилем, что и Android-приложение.
- При запуске очищает служебные каталоги Android на разделах PARAVIS и DATA:
`Android`, `.thumbnails`, `.android_secure`, `.trash-storage`, `.Trash-*`
и пустые медиакаталоги (`Music`, `Pictures`, `Download`, `DCIM` и т. п.).
`LOST.DIR` очищается, но остаётся скрытой и системной, чтобы Android не
создавала её заново на виду.
- Bootice, xcopy и скрипт создания MBR для GRUB2 вызываются так же, как в
AutoIt-версии. Скрипт:
`\efi\Paravis\Boot\grub2\bios\make-paravis-mbr.ps1`.
+172
View File
@@ -0,0 +1,172 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 Paravis
#include "cleanup.h"
#include "util.h"
#include <windows.h>
#include <string>
#include <vector>
namespace {
bool EqualsNoCase(const std::wstring& value, const wchar_t* expected)
{
return _wcsicmp(value.c_str(), expected) == 0;
}
bool StartsWithNoCase(const std::wstring& value, const wchar_t* prefix)
{
size_t length = wcslen(prefix);
return value.size() >= length &&
_wcsnicmp(value.c_str(), prefix, length) == 0;
}
bool IsServiceDir(const std::wstring& name)
{
return EqualsNoCase(name, L"Android") ||
EqualsNoCase(name, L".thumbnails") ||
EqualsNoCase(name, L".android_secure") ||
EqualsNoCase(name, L".trash-storage") ||
StartsWithNoCase(name, L".Trash-");
}
bool IsMediaDir(const std::wstring& name)
{
static const wchar_t* const kNames[] = {
L"Music", L"Podcasts", L"Ringtones", L"Alarms",
L"Notifications", L"Pictures", L"Movies", L"Download",
L"DCIM", L"Documents", L"Audiobooks", L"Recordings"
};
for (const wchar_t* candidate : kNames) {
if (EqualsNoCase(name, candidate)) {
return true;
}
}
return false;
}
std::vector<std::wstring> ListChildren(const std::wstring& dir)
{
std::vector<std::wstring> result;
WIN32_FIND_DATAW data{};
HANDLE handle = FindFirstFileW((dir + L"\\*").c_str(), &data);
if (handle == INVALID_HANDLE_VALUE) {
return result;
}
do {
if (wcscmp(data.cFileName, L".") != 0 &&
wcscmp(data.cFileName, L"..") != 0) {
result.emplace_back(data.cFileName);
}
} while (FindNextFileW(handle, &data));
FindClose(handle);
return result;
}
bool RemoveTree(const std::wstring& path)
{
DWORD attributes = GetFileAttributesW(path.c_str());
if (attributes == INVALID_FILE_ATTRIBUTES) {
return false;
}
if (attributes & FILE_ATTRIBUTE_DIRECTORY) {
for (const std::wstring& child : ListChildren(path)) {
RemoveTree(path + L"\\" + child);
}
SetFileAttributesW(path.c_str(), FILE_ATTRIBUTE_NORMAL);
return RemoveDirectoryW(path.c_str()) != 0;
}
SetFileAttributesW(path.c_str(), FILE_ATTRIBUTE_NORMAL);
return DeleteFileW(path.c_str()) != 0;
}
void ClearContents(const std::wstring& dir)
{
for (const std::wstring& child : ListChildren(dir)) {
RemoveTree(dir + L"\\" + child);
}
}
bool IsDirectoryEmpty(const std::wstring& dir)
{
return ListChildren(dir).empty();
}
void PruneEmptyDirs(const std::wstring& dir)
{
for (const std::wstring& child : ListChildren(dir)) {
std::wstring path = dir + L"\\" + child;
DWORD attributes = GetFileAttributesW(path.c_str());
if (attributes == INVALID_FILE_ATTRIBUTES ||
!(attributes & FILE_ATTRIBUTE_DIRECTORY)) {
continue;
}
PruneEmptyDirs(path);
if (IsDirectoryEmpty(path)) {
RemoveDirectoryW(path.c_str());
}
}
}
void EnsureHiddenSystem(const std::wstring& path)
{
DWORD attributes = GetFileAttributesW(path.c_str());
if (attributes != INVALID_FILE_ATTRIBUTES) {
SetFileAttributesW(path.c_str(),
attributes | FILE_ATTRIBUTE_HIDDEN |
FILE_ATTRIBUTE_SYSTEM);
}
}
void CleanRoot(const std::wstring& root)
{
if (root.empty()) {
return;
}
for (const std::wstring& name : ListChildren(root)) {
std::wstring path = root + name;
DWORD attributes = GetFileAttributesW(path.c_str());
if (attributes == INVALID_FILE_ATTRIBUTES ||
!(attributes & FILE_ATTRIBUTE_DIRECTORY)) {
continue;
}
if (EqualsNoCase(name, L"LOST.DIR")) {
ClearContents(path);
EnsureHiddenSystem(path);
DebugLog(L"cleanup: cleared LOST.DIR in %s", root.c_str());
continue;
}
if (IsServiceDir(name)) {
if (RemoveTree(path)) {
DebugLog(L"cleanup: removed %s", path.c_str());
}
continue;
}
if (IsMediaDir(name)) {
std::wstring thumbs = path + L"\\.thumbnails";
if (GetFileAttributesW(thumbs.c_str()) != INVALID_FILE_ATTRIBUTES) {
RemoveTree(thumbs);
}
PruneEmptyDirs(path);
if (IsDirectoryEmpty(path) && RemoveDirectoryW(path.c_str())) {
DebugLog(L"cleanup: removed %s", path.c_str());
}
}
}
}
} // namespace
void CleanAndroidJunk(const std::wstring& paravisRoot,
const std::wstring& dataRoot)
{
CleanRoot(paravisRoot);
if (!dataRoot.empty() &&
_wcsicmp(paravisRoot.c_str(), dataRoot.c_str()) != 0) {
CleanRoot(dataRoot);
}
}
+11
View File
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 Paravis
#pragma once
#include <string>
// Removes Android-created service folders and empty media directories from
// the PARAVIS and DATA roots. LOST.DIR is emptied and kept hidden/system.
void CleanAndroidJunk(const std::wstring& paravisRoot,
const std::wstring& dataRoot);
+13
View File
@@ -2,6 +2,7 @@
// Copyright (c) 2026 Paravis
#include "app.h"
#include "cleanup.h"
#include "util.h"
#include <windowsx.h>
@@ -443,6 +444,18 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int)
return 0;
}
std::wstring dataMarker = FindDataMarker();
if (dataMarker.empty()) {
MessageBoxW(nullptr,
L"Не найден маркер ISO\\Ventoy\\NOT.DEL на разделе DATA.\r\n"
L"Диск не похож на сборку Paravis.",
kWindowTitle,
MB_ICONERROR | MB_OK | MB_SETFOREGROUND | MB_TOPMOST);
return 0;
}
std::wstring dataRoot = dataMarker.substr(0, 3);
CleanAndroidJunk(app.disk + L"\\", dataRoot);
WNDCLASSEXW windowClass{};
windowClass.cbSize = sizeof(windowClass);
windowClass.lpfnWndProc = MainProc;