-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
MemStickScreen.cpp
630 lines (530 loc) · 22.8 KB
/
MemStickScreen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
// Copyright (c) 2013- PPSSPP Project.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 2.0 or later versions.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License 2.0 for more details.
// A copy of the GPL 2.0 should have been included with the program.
// If not, see http://www.gnu.org/licenses/
// Official git repository and contact information can be found at
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
#include "ppsspp_config.h"
#include "android/jni/app-android.h"
#include "Common/Log.h"
#include "Common/UI/UI.h"
#include "Common/UI/View.h"
#include "Common/UI/ViewGroup.h"
#include "Common/StringUtils.h"
#include "Common/System/System.h"
#include "Common/System/Request.h"
#include "Common/System/NativeApp.h"
#include "Common/System/Display.h"
#include "Common/System/OSD.h"
#include "Common/Data/Text/I18n.h"
#include "Common/Data/Text/Parsers.h"
#include "Common/File/AndroidStorage.h"
#include "Common/File/FileUtil.h"
#include "Common/File/Path.h"
#include "Common/File/DiskFree.h"
#include "Common/Thread/ThreadManager.h"
#include "Core/Config.h"
#include "Core/Reporting.h"
#include "Core/System.h"
#include "Core/Util/GameManager.h"
#include "Core/Util/MemStick.h"
#include "UI/MemStickScreen.h"
#include "UI/MainScreen.h"
#include "UI/MiscScreens.h"
#include "UI/OnScreenDisplay.h"
static std::string FormatSpaceString(int64_t space) {
if (space >= 0) {
char buffer[50];
NiceSizeFormat(space, buffer, sizeof(buffer));
return buffer;
} else {
return "N/A";
}
}
MemStickScreen::MemStickScreen(bool initialSetup)
: initialSetup_(initialSetup) {
#if PPSSPP_PLATFORM(ANDROID)
// Let's only offer the browse-for-folder choice on Android 10 or later.
// Earlier versions often don't really have working folder browsers.
storageBrowserWorking_ = System_GetPropertyInt(SYSPROP_SYSTEMVERSION) >= 29;
#else
// For testing UI only
storageBrowserWorking_ = true;
#endif
if (initialSetup_) {
// Preselect current choice.
if (System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
choice_ = CHOICE_BROWSE_FOLDER;
} else {
WARN_LOG_REPORT(SYSTEM, "Scoped storage not enabled - shouldn't be in MemStickScreen at initial setup");
choice_ = CHOICE_STORAGE_ROOT;
// Shouldn't really be here in initial setup.
}
} else {
// Detect the current choice, so it's preselected in the UI.
#if PPSSPP_PLATFORM(UWP)
if (g_Config.memStickDirectory == g_Config.internalDataDirectory) {
#else
if (g_Config.memStickDirectory == Path(g_extFilesDir)) {
#endif
choice_ = CHOICE_PRIVATE_DIRECTORY;
} else if (g_Config.memStickDirectory == Path(g_externalDir)) {
choice_ = CHOICE_STORAGE_ROOT;
} else if (storageBrowserWorking_) {
choice_ = CHOICE_BROWSE_FOLDER;
} else {
choice_ = CHOICE_SET_MANUAL;
}
}
}
static void AddExplanation(UI::ViewGroup *viewGroup, MemStickScreen::Choice choice, UI::View *extraView = nullptr) {
auto iz = GetI18NCategory(I18NCat::MEMSTICK);
using namespace UI;
int flags = FLAG_WRAP_TEXT;
UI::ViewGroup *holder = new UI::LinearLayout(ORIENT_VERTICAL);
UI::ViewGroup *indentHolder = new UI::LinearLayout(ORIENT_HORIZONTAL);
indentHolder->Add(new Spacer(20.0));
indentHolder->Add(holder);
viewGroup->Add(indentHolder);
if (extraView) {
holder->Add(extraView);
}
switch (choice) {
case MemStickScreen::CHOICE_STORAGE_ROOT:
// Old school choice
holder->Add(new TextView(iz->T("DataWillStay", "Data will stay even if you uninstall PPSSPP"), flags, false))->SetBullet(true);
holder->Add(new TextView(iz->T("DataCanBeShared", "Data can be shared between PPSSPP regular/Gold"), flags, false))->SetBullet(true);
holder->Add(new TextView(iz->T("EasyUSBAccess", "Easy USB access"), flags, false))->SetBullet(true);
break;
case MemStickScreen::CHOICE_BROWSE_FOLDER:
holder->Add(new TextView(iz->T("DataWillStay", "Data will stay even if you uninstall PPSSPP"), flags, false))->SetBullet(true);
holder->Add(new TextView(iz->T("DataCanBeShared", "Data can be shared between PPSSPP regular/Gold"), flags, false))->SetBullet(true);
#if !PPSSPP_PLATFORM(UWP)
holder->Add(new TextView(iz->T("EasyUSBAccess", "Easy USB access"), flags, false))->SetBullet(true);
#endif
break;
case MemStickScreen::CHOICE_PRIVATE_DIRECTORY:
// Consider https://www.compart.com/en/unicode/U+26A0 (unicode warning sign?)? or a graphic?
holder->Add(new TextView(iz->T("DataWillBeLostOnUninstall", "Warning! Data will be lost when you uninstall PPSSPP!"), flags, false))->SetBullet(true);
holder->Add(new TextView(iz->T("DataCannotBeShared", "Data CANNOT be shared between PPSSPP regular/Gold!"), flags, false))->SetBullet(true);
#if !PPSSPP_PLATFORM(UWP)
#if GOLD
holder->Add(new TextView(iz->T("USBAccessThroughGold", "USB access through Android/data/org.ppsspp.ppssppgold/files"), flags, false))->SetBullet(true);
#else
holder->Add(new TextView(iz->T("USBAccessThrough", "USB access through Android/data/org.ppsspp.ppsspp/files"), flags, false))->SetBullet(true);
#endif
#endif
break;
case MemStickScreen::CHOICE_SET_MANUAL:
default:
holder->Add(new TextView(iz->T("EasyUSBAccess", "Easy USB access"), flags, false))->SetBullet(true);
// What more?
// Should we have a special text here? It'll popup a text window for editing.
break;
}
}
void MemStickScreen::CreateViews() {
using namespace UI;
auto di = GetI18NCategory(I18NCat::DIALOG);
auto iz = GetI18NCategory(I18NCat::MEMSTICK);
Margins actionMenuMargins(15, 0, 15, 0);
root_ = new LinearLayout(ORIENT_HORIZONTAL);
Spacer *spacerColumn = new Spacer(new LinearLayoutParams(20.0, FILL_PARENT, 0.0f));
ScrollView *mainColumnScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(1.0));
ViewGroup *mainColumn = new LinearLayoutList(ORIENT_VERTICAL);
mainColumnScroll->Add(mainColumn);
root_->Add(spacerColumn);
root_->Add(mainColumnScroll);
if (initialSetup_) {
mainColumn->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 12.0f, 0.0f)));
mainColumn->Add(new TextView(iz->T("Welcome to PPSSPP!"), ALIGN_LEFT, false));
}
mainColumn->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 18.0f, 0.0f)));
mainColumn->Add(new TextView(iz->T("MemoryStickDescription", "Choose where to keep PSP data (Memory Stick)"), ALIGN_LEFT, false));
mainColumn->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 18.0f, 0.0f)));
ViewGroup *subColumns = new LinearLayoutList(ORIENT_HORIZONTAL);
mainColumn->Add(subColumns);
ViewGroup *leftColumn = new LinearLayoutList(ORIENT_VERTICAL, new LinearLayoutParams(1.0));
subColumns->Add(leftColumn);
ViewGroup *rightColumnItems = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(220, FILL_PARENT, actionMenuMargins));
subColumns->Add(rightColumnItems);
// For legacy Android systems, so you can switch back to the old ways if you move to SD or something.
// Trying to avoid needing a scroll view, so only showing the explanation for one option at a time.
#if !PPSSPP_PLATFORM(UWP)
if (!System_GetPropertyBool(SYSPROP_ANDROID_SCOPED_STORAGE)) {
leftColumn->Add(new RadioButton(&choice_, CHOICE_STORAGE_ROOT, iz->T("Use PSP folder at root of storage")))->OnClick.Handle(this, &MemStickScreen::OnChoiceClick);
if (choice_ == CHOICE_STORAGE_ROOT) {
AddExplanation(leftColumn, (MemStickScreen::Choice)choice_);
}
}
#endif
if (storageBrowserWorking_) {
leftColumn->Add(new RadioButton(&choice_, CHOICE_BROWSE_FOLDER, iz->T("Create or Choose a PSP folder")))->OnClick.Handle(this, &MemStickScreen::OnChoiceClick);
// TODO: Show current folder here if we have one set.
} else {
leftColumn->Add(new RadioButton(&choice_, CHOICE_SET_MANUAL, iz->T("Manually specify PSP folder")))->OnClick.Handle(this, &MemStickScreen::OnChoiceClick);
leftColumn->Add(new TextView(iz->T("DataWillStay", "Data will stay even if you uninstall PPSSPP.")))->SetBullet(true);
leftColumn->Add(new TextView(iz->T("DataCanBeShared", "Data can be shared between PPSSPP regular/Gold.")))->SetBullet(true);
// TODO: Show current folder here if we have one set.
}
errorNoticeView_ = leftColumn->Add(new NoticeView(NoticeLevel::WARN, iz->T("Cancelled - try again"), ""));
errorNoticeView_->SetVisibility(UI::V_GONE);
if (choice_ == CHOICE_BROWSE_FOLDER || choice_ == CHOICE_SET_MANUAL) {
UI::View *extraView = nullptr;
if (!g_Config.memStickDirectory.empty()) {
extraView = new TextView(StringFromFormat(" %s: %s", iz->T("Current"), g_Config.memStickDirectory.ToVisualString().c_str()), ALIGN_LEFT, false);
}
AddExplanation(leftColumn, (MemStickScreen::Choice)choice_, extraView);
}
std::string privateString = iz->T("Use App Private Data");
if (initialSetup_) {
privateString = StringFromFormat("%s (%s)", iz->T("Skip for now"), privateString.c_str());
}
leftColumn->Add(new RadioButton(&choice_, CHOICE_PRIVATE_DIRECTORY, privateString))->OnClick.Handle(this, &MemStickScreen::OnChoiceClick);
if (choice_ == CHOICE_PRIVATE_DIRECTORY) {
AddExplanation(leftColumn, (MemStickScreen::Choice)choice_);
}
leftColumn->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 12.0f, 0.0f)));
const char *confirmButtonText = nullptr;
ImageID confirmButtonImage = ImageID::invalid();
switch (choice_) {
case CHOICE_BROWSE_FOLDER:
confirmButtonText = di->T("OK");
confirmButtonImage = ImageID("I_FOLDER_OPEN");
break;
case CHOICE_PRIVATE_DIRECTORY:
if (initialSetup_) {
confirmButtonText = di->T("Skip");
confirmButtonImage = ImageID("I_WARNING");
} else {
confirmButtonText = di->T("OK");
}
break;
case CHOICE_STORAGE_ROOT:
case CHOICE_SET_MANUAL:
default:
confirmButtonText = di->T("OK");
break;
}
rightColumnItems->Add(new UI::Choice(confirmButtonText, confirmButtonImage))->OnClick.Handle<MemStickScreen>(this, &MemStickScreen::OnConfirmClick);
rightColumnItems->Add(new Spacer(new LinearLayoutParams(FILL_PARENT, 12.0f, 0.0f)));
if (!initialSetup_) {
rightColumnItems->Add(new UI::Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
}
if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) != DEVICE_TYPE_TV) {
rightColumnItems->Add(new UI::Choice(iz->T("WhatsThis", "What's this?")))->OnClick.Handle<MemStickScreen>(this, &MemStickScreen::OnHelp);
}
INFO_LOG(SYSTEM, "MemStickScreen: initialSetup=%d", (int)initialSetup_);
}
UI::EventReturn MemStickScreen::OnHelp(UI::EventParams ¶ms) {
// I'm letting the old redirect handle this one, as the target is within /docs on the website,
// and that structure may change a bit.
System_LaunchUrl(LaunchUrlType::BROWSER_URL, "https://www.ppsspp.org/guide_storage.html");
return UI::EVENT_DONE;
}
UI::EventReturn MemStickScreen::OnChoiceClick(UI::EventParams ¶ms) {
// Change the confirm button to match the choice,
// and change the text that we show.
RecreateViews();
return UI::EVENT_DONE;
}
UI::EventReturn MemStickScreen::OnConfirmClick(UI::EventParams ¶ms) {
switch (choice_) {
case CHOICE_SET_MANUAL:
return SetFolderManually(params);
case CHOICE_STORAGE_ROOT:
return UseStorageRoot(params);
case CHOICE_PRIVATE_DIRECTORY:
return UseInternalStorage(params);
case CHOICE_BROWSE_FOLDER:
return Browse(params);
}
return UI::EVENT_DONE;
}
UI::EventReturn MemStickScreen::SetFolderManually(UI::EventParams ¶ms) {
// The old way, from before scoped storage.
#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(SWITCH)
auto sy = GetI18NCategory(I18NCat::SYSTEM);
System_InputBoxGetString(GetRequesterToken(), sy->T("Memory Stick Folder"), g_Config.memStickDirectory.ToString(), [&](const std::string &value, int) {
auto sy = GetI18NCategory(I18NCat::SYSTEM);
auto di = GetI18NCategory(I18NCat::DIALOG);
std::string newPath = value;
size_t pos = newPath.find_last_not_of("/");
// Gotta have at least something but a /, and also needs to start with a /.
if (newPath.empty() || pos == newPath.npos || newPath[0] != '/') {
settingInfo_->Show(sy->T("ChangingMemstickPathInvalid", "That path couldn't be used to save Memory Stick files."), nullptr);
return;
}
if (pos != newPath.size() - 1) {
newPath = newPath.substr(0, pos + 1);
}
if (newPath.empty()) {
// Reuse below message instead of adding yet another string.
System_Toast(sy->T("Path does not exist!"));
return;
}
Path pendingMemStickFolder(newPath);
if (!File::Exists(pendingMemStickFolder)) {
// Try to fix the path string, apparently some users got used to leaving out the /.
if (newPath[0] != '/') {
newPath = "/" + newPath;
}
pendingMemStickFolder = Path(newPath);
}
if (!File::Exists(pendingMemStickFolder) && pendingMemStickFolder.Type() == PathType::NATIVE) {
// Still no path? Try to automatically fix the case.
std::string oldNewPath = newPath;
FixPathCase(Path(""), newPath, FixPathCaseBehavior::FPC_FILE_MUST_EXIST);
if (oldNewPath != newPath) {
NOTICE_LOG(IO, "Fixed path case: %s -> %s", oldNewPath.c_str(), newPath.c_str());
pendingMemStickFolder = Path(newPath);
} else {
NOTICE_LOG(IO, "Failed to fix case of path %s (result: %s)", newPath.c_str(), oldNewPath.c_str());
}
}
if (pendingMemStickFolder == g_Config.memStickDirectory) {
// Same directory as before - all good. Nothing to do.
TriggerFinish(DialogResult::DR_OK);
return;
}
if (!File::Exists(pendingMemStickFolder)) {
System_Toast(sy->T("Path does not exist!"));
return;
}
screenManager()->push(new ConfirmMemstickMoveScreen(pendingMemStickFolder, false));
});
#endif
return UI::EVENT_DONE;
}
UI::EventReturn MemStickScreen::UseInternalStorage(UI::EventParams ¶ms) {
#if PPSSPP_PLATFORM(UWP)
Path pendingMemStickFolder = g_Config.internalDataDirectory;
#else
Path pendingMemStickFolder = Path(g_extFilesDir);
#endif
if (initialSetup_) {
// There's not gonna be any files here in this case since it's a fresh install.
// Let's just accept it and move on. No need to move files either.
if (SwitchMemstickFolderTo(pendingMemStickFolder)) {
TriggerFinish(DialogResult::DR_OK);
} else {
// This can't really happen?? Not worth making an error message.
ERROR_LOG_REPORT(SYSTEM, "Could not switch memstick path in setup (internal)");
}
// Don't have a confirmation dialog that would otherwise do it for us, need to just switch directly to the main screen.
screenManager()->switchScreen(new MainScreen());
} else if (pendingMemStickFolder != g_Config.memStickDirectory) {
// Always ask for confirmation when called from the UI. Likely there's already some data.
screenManager()->push(new ConfirmMemstickMoveScreen(pendingMemStickFolder, false));
} else {
// User chose the same directory it's already in. Let's just bail.
TriggerFinish(DialogResult::DR_OK);
}
return UI::EVENT_DONE;
}
UI::EventReturn MemStickScreen::UseStorageRoot(UI::EventParams ¶ms) {
Path pendingMemStickFolder = Path(g_externalDir);
if (initialSetup_) {
// There's not gonna be any files here in this case since it's a fresh install.
// Let's just accept it and move on. No need to move files either.
if (SwitchMemstickFolderTo(pendingMemStickFolder)) {
TriggerFinish(DialogResult::DR_OK);
} else {
// This can't really happen?? Not worth making an error message.
ERROR_LOG_REPORT(SYSTEM, "Could not switch memstick path in setup");
}
} else if (pendingMemStickFolder != g_Config.memStickDirectory) {
// Always ask for confirmation when called from the UI. Likely there's already some data.
screenManager()->push(new ConfirmMemstickMoveScreen(pendingMemStickFolder, false));
} else {
// User chose the same directory it's already in. Let's just bail.
TriggerFinish(DialogResult::DR_OK);
}
return UI::EVENT_DONE;
}
UI::EventReturn MemStickScreen::Browse(UI::EventParams ¶ms) {
auto mm = GetI18NCategory(I18NCat::MAINMENU);
System_BrowseForFolder(GetRequesterToken(), mm->T("Choose folder"), [=](const std::string &value, int) {
Path pendingMemStickFolder = Path(value);
INFO_LOG(SYSTEM, "Got folder: '%s'", pendingMemStickFolder.c_str());
// Browse finished. Let's pop up the confirmation dialog.
if (!pendingMemStickFolder.empty() && pendingMemStickFolder == g_Config.memStickDirectory && File::IsDirectory(pendingMemStickFolder)) {
auto iz = GetI18NCategory(I18NCat::MEMSTICK);
// Not sure how this could happen, but let's go with it.
g_OSD.Show(OSDType::MESSAGE_SUCCESS, iz->T("Done!"));
done_ = true;
return;
}
errorNoticeView_->SetVisibility(UI::V_GONE);
screenManager()->push(new ConfirmMemstickMoveScreen(pendingMemStickFolder, initialSetup_));
}, [=]() {
errorNoticeView_->SetVisibility(UI::V_VISIBLE);
});
return UI::EVENT_DONE;
}
void MemStickScreen::dialogFinished(const Screen *dialog, DialogResult result) {
if (result == DialogResult::DR_OK) {
INFO_LOG(SYSTEM, "Confirmation screen done - moving on.");
// There's a screen manager bug if we call TriggerFinish directly.
// Can't be bothered right now, so we pick this up in update().
done_ = true;
}
// otherwise, we just keep going.
}
void MemStickScreen::update() {
UIDialogScreenWithBackground::update();
if (done_) {
TriggerFinish(DialogResult::DR_OK);
done_ = false;
}
}
ConfirmMemstickMoveScreen::ConfirmMemstickMoveScreen(Path newMemstickFolder, bool initialSetup)
: newMemstickFolder_(newMemstickFolder), initialSetup_(initialSetup) {
existingFilesInNewFolder_ = FolderSeemsToBeUsed(newMemstickFolder);
if (initialSetup_) {
moveData_ = false;
}
}
ConfirmMemstickMoveScreen::~ConfirmMemstickMoveScreen() {
if (moveDataTask_) {
INFO_LOG(SYSTEM, "Move Data task still running, blocking on it");
moveDataTask_->BlockUntilReady();
delete moveDataTask_;
}
}
void ConfirmMemstickMoveScreen::CreateViews() {
using namespace UI;
auto sy = GetI18NCategory(I18NCat::SYSTEM);
auto iz = GetI18NCategory(I18NCat::MEMSTICK);
root_ = new LinearLayout(ORIENT_HORIZONTAL);
Path oldMemstickFolder = g_Config.memStickDirectory;
Spacer *spacerColumn = new Spacer(new LinearLayoutParams(20.0, FILL_PARENT, 0.0f));
ViewGroup *leftColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0));
ViewGroup *rightColumn = new LinearLayout(ORIENT_VERTICAL, new LinearLayoutParams(1.0));
root_->Add(spacerColumn);
root_->Add(leftColumn);
root_->Add(rightColumn);
int64_t freeSpaceNew;
int64_t freeSpaceOld;
free_disk_space(newMemstickFolder_, freeSpaceNew);
free_disk_space(oldMemstickFolder, freeSpaceOld);
leftColumn->Add(new TextView(iz->T("Selected PSP Data Folder"), ALIGN_LEFT, false));
if (!initialSetup_) {
leftColumn->Add(new NoticeView(NoticeLevel::WARN, iz->T("PPSSPP will restart after the change"), ""));
}
leftColumn->Add(new TextView(newMemstickFolder_.ToVisualString(), ALIGN_LEFT, false));
std::string newFreeSpaceText = std::string(iz->T("Free space")) + ": " + FormatSpaceString(freeSpaceNew);
leftColumn->Add(new TextView(newFreeSpaceText, ALIGN_LEFT, false));
if (existingFilesInNewFolder_) {
leftColumn->Add(new NoticeView(NoticeLevel::SUCCESS, iz->T("Already contains PSP data"), ""));
if (!moveData_) {
leftColumn->Add(new NoticeView(NoticeLevel::INFO, iz->T("No data will be changed"), ""));
}
}
if (!error_.empty()) {
leftColumn->Add(new TextView(error_, ALIGN_LEFT, false));
}
if (!oldMemstickFolder.empty()) {
std::string oldFreeSpaceText = std::string(iz->T("Free space")) + ": " + FormatSpaceString(freeSpaceOld);
rightColumn->Add(new TextView(std::string(iz->T("Current")) + ":", ALIGN_LEFT, false));
rightColumn->Add(new TextView(oldMemstickFolder.ToVisualString(), ALIGN_LEFT, false));
rightColumn->Add(new TextView(oldFreeSpaceText, ALIGN_LEFT, false));
}
if (moveDataTask_) {
progressView_ = leftColumn->Add(new TextView(progressReporter_.Format()));
} else {
progressView_ = nullptr;
}
if (!moveDataTask_) {
if (!initialSetup_) {
leftColumn->Add(new CheckBox(&moveData_, iz->T("Move Data")))->OnClick.Handle(this, &ConfirmMemstickMoveScreen::OnMoveDataClick);
}
auto di = GetI18NCategory(I18NCat::DIALOG);
leftColumn->Add(new Choice(di->T("OK")))->OnClick.Handle(this, &ConfirmMemstickMoveScreen::OnConfirm);
leftColumn->Add(new Choice(di->T("Back")))->OnClick.Handle<UIScreen>(this, &UIScreen::OnBack);
}
}
UI::EventReturn ConfirmMemstickMoveScreen::OnMoveDataClick(UI::EventParams ¶ms) {
RecreateViews();
return UI::EVENT_DONE;
}
void ConfirmMemstickMoveScreen::update() {
UIDialogScreenWithBackground::update();
auto iz = GetI18NCategory(I18NCat::MEMSTICK);
if (moveDataTask_) {
if (progressView_) {
progressView_->SetText(progressReporter_.Format());
}
MoveResult *result = moveDataTask_->Poll();
if (result) {
if (result->success) {
progressReporter_.SetProgress(iz->T("Done!"));
INFO_LOG(SYSTEM, "Move data task finished successfully!");
// Succeeded!
FinishFolderMove();
} else {
progressReporter_.SetProgress(iz->T("Failed to move some files!"));
INFO_LOG(SYSTEM, "Move data task failed!");
// What do we do here? We might be in the middle of a move... Bad.
RecreateViews();
}
delete moveDataTask_;
moveDataTask_ = nullptr;
}
}
}
UI::EventReturn ConfirmMemstickMoveScreen::OnConfirm(UI::EventParams ¶ms) {
// Transfer all the files in /PSP from the original directory.
// Should probably be done on a background thread so we can show some UI.
// So we probably need another screen for this with a progress bar..
// If the directory itself is called PSP, don't go below.
if (moveData_) {
progressReporter_.SetProgress(T(I18NCat::MEMSTICK, "Starting move..."));
moveDataTask_ = Promise<MoveResult *>::Spawn(&g_threadManager, [&]() -> MoveResult * {
Path moveSrc = g_Config.memStickDirectory;
Path moveDest = newMemstickFolder_;
return MoveDirectoryContentsSafe(moveSrc, moveDest, progressReporter_);
}, TaskType::IO_BLOCKING, TaskPriority::HIGH);
RecreateViews();
} else {
FinishFolderMove();
}
return UI::EVENT_DONE;
}
void ConfirmMemstickMoveScreen::FinishFolderMove() {
auto ms = GetI18NCategory(I18NCat::MEMSTICK);
Path oldMemstickFolder = g_Config.memStickDirectory;
// Successful so far, switch the memstick folder.
if (!SwitchMemstickFolderTo(newMemstickFolder_)) {
// TODO: More precise errors.
error_ = ms->T("That folder doesn't work as a memstick folder.");
return;
}
// If the chosen folder already had a config, reload it!
g_Config.Load();
// If the current browser directory is the old memstick folder, drop it.
if (g_Config.currentDirectory == oldMemstickFolder) {
g_Config.currentDirectory = g_Config.defaultCurrentDirectory;
}
PostLoadConfig();
if (!initialSetup_) {
// We restart the app here, to get the new settings.
System_RestartApp("");
} else {
// This is initial setup, we now switch to the main screen, if we were successful
// (which we better have been...)
if (g_Config.Save("MemstickPathChanged")) {
// TriggerFinish(DialogResult::DR_OK);
screenManager()->switchScreen(new MainScreen());
} else {
error_ = ms->T("Failed to save config");
RecreateViews();
}
}
}