Skip to content

Commit bce8a7f

Browse files
committed
main: Show warning on low space
1 parent 5900bcb commit bce8a7f

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

main.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,33 @@ int main(void)
152152
// Main menu always exists
153153
main_menu_activate();
154154

155+
// If storage space is below some % on any partition, show a warning
156+
char warning_text[128];
157+
const char *drive_letters[] = {"C:\\", "E:\\", "F:\\", "G:\\", "X:\\", "Y:\\", "Z:\\"};
158+
Menu menu_warning = {
159+
.item = (MenuItem *)&(MenuItem){warning_text, NULL},
160+
.item_count = 1,
161+
.selected_index = 0,
162+
.scroll_offset = 0};
163+
int char_offset = 0;
164+
for (unsigned int i = 0; i < sizeof(drive_letters) / sizeof(drive_letters[0]); i++) {
165+
ULARGE_INTEGER total_bytes, free_bytes;
166+
if (GetDiskFreeSpaceEx(drive_letters[i], &free_bytes, &total_bytes, NULL)) {
167+
ULONGLONG percent_free = ((free_bytes.QuadPart / 1024ULL) * 100ULL) / (total_bytes.QuadPart / 1024ULL);
168+
if (percent_free < 5ULL) {
169+
if (char_offset == 0) {
170+
char_offset += snprintf(&warning_text[char_offset], sizeof(warning_text) - char_offset, "Warning\nLow storage space on partitions:");
171+
}
172+
char_offset += snprintf(&warning_text[char_offset], sizeof(warning_text) - char_offset, " %c,", drive_letters[i][0]);
173+
}
174+
}
175+
}
176+
if (char_offset > 0) {
177+
// Remove the last comma
178+
warning_text[char_offset - 1] = '\0';
179+
menu_push(&menu_warning);
180+
}
181+
155182
// Main running loop
156183
bool running = true;
157184
SDL_Event e;

0 commit comments

Comments
 (0)