Skip to content

Commit

Permalink
- Fix saving to a previously unavailable device
Browse files Browse the repository at this point in the history
- Fix device traversal / show all devices
  • Loading branch information
emukidid committed Aug 29, 2017
1 parent 4c062f3 commit 2075d18
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 19 deletions.
6 changes: 5 additions & 1 deletion cube/swiss/source/config/config.c
Expand Up @@ -96,7 +96,8 @@ bool config_set_device() {
DEVICEHANDLER_INTERFACE *configDevice = getDeviceByUniqueId(swissSettings.configDeviceId);
devices[DEVICE_CONFIG] = NULL;
if(configDevice != NULL) {
if((configDevice->features & FEAT_WRITE) && deviceHandler_getDeviceAvailable(configDevice)) {
if((configDevice->features & FEAT_WRITE) && (configDevice->test())) {
deviceHandler_setDeviceAvailable(configDevice, true);
devices[DEVICE_CONFIG] = configDevice;
}
}
Expand All @@ -105,10 +106,13 @@ bool config_set_device() {
if(devices[DEVICE_CONFIG] == NULL) {
return false;
}
print_gecko("Save device is %s\r\n", devices[DEVICE_CONFIG]->deviceName);
deviceHandler_setStatEnabled(0);
// If we're not using this device already, init it.
if(devices[DEVICE_CONFIG] != devices[DEVICE_CUR]) {
print_gecko("Save device is not current, current is (%s)\r\n", devices[DEVICE_CUR] == NULL ? "NULL":devices[DEVICE_CUR]->deviceName);
if(!devices[DEVICE_CONFIG]->init(devices[DEVICE_CONFIG]->initial)) {
print_gecko("Save device failed to init\r\n");
deviceHandler_setStatEnabled(1);
return false;
}
Expand Down
6 changes: 4 additions & 2 deletions cube/swiss/source/devices/memcard/deviceHandler-CARD.c
Expand Up @@ -483,11 +483,13 @@ s32 deviceHandler_CARD_closeFile(file_handle* file) {
}

bool deviceHandler_CARD_test_a() {
return (initialize_card(0)==CARD_ERROR_READY);
s32 memSize = 0, sectSize = 0;
return ((initialize_card(0)==CARD_ERROR_READY) && (CARD_ProbeEx(0, &memSize,&sectSize)==CARD_ERROR_READY));
}

bool deviceHandler_CARD_test_b() {
return (initialize_card(1)==CARD_ERROR_READY);
s32 memSize = 0, sectSize = 0;
return ((initialize_card(1)==CARD_ERROR_READY) && (CARD_ProbeEx(1, &memSize,&sectSize)==CARD_ERROR_READY));
}

DEVICEHANDLER_INTERFACE __device_card_a = {
Expand Down
3 changes: 2 additions & 1 deletion cube/swiss/source/main.c
Expand Up @@ -502,6 +502,7 @@ int main ()
if(allDevices[i] != NULL && (allDevices[i]->features & FEAT_BOOT_DEVICE)) {
print_gecko("Testing device %s\r\n", allDevices[i]->deviceName);
if(allDevices[i]->test()) {
deviceHandler_setDeviceAvailable(allDevices[i], true);
devices[DEVICE_CUR] = allDevices[i];
break;
}
Expand Down Expand Up @@ -598,7 +599,7 @@ void populateDeviceAvailability() {
}
int i;
for(i = 0; i < MAX_DEVICES; i++) {
if(allDevices[i] != NULL) {
if(allDevices[i] != NULL && !deviceHandler_getDeviceAvailable(allDevices[i])) {
print_gecko("Checking device availability for device %s\r\n", allDevices[i]->deviceName);
deviceHandler_setDeviceAvailable(allDevices[i], allDevices[i]->test());
}
Expand Down
48 changes: 33 additions & 15 deletions cube/swiss/source/swiss.c
Expand Up @@ -1509,25 +1509,37 @@ void select_device(int type)

int curDevice = 0;
int inAdvanced = 0, showAllDevices = 0;
int direction = 1;
int direction = 0;

// Find the first device that meets the requiredFeatures and is available
while((allDevices[curDevice] == NULL) || !(deviceHandler_getDeviceAvailable(allDevices[curDevice])||showAllDevices) || !(allDevices[curDevice]->features & requiredFeatures)) {
curDevice ++;
if( (curDevice >= MAX_DEVICES)){
curDevice = 0;
}
}

while(1) {
// Go to the first device available if we're not showing all devices
int i = curDevice;
i+= direction;

if(i < 0) i = MAX_DEVICES;
else if (i > MAX_DEVICES) i = 0;
while(1) {
if(allDevices[i] != NULL && (deviceHandler_getDeviceAvailable(allDevices[i])||showAllDevices) && (allDevices[i]->features & requiredFeatures)) {
curDevice = i;
break;
if(direction != 0) {
if(direction > 0) {
curDevice = allDevices[curDevice+1] == NULL ? 0 : curDevice+1;
}
else {
curDevice = curDevice > 0 ? curDevice-1 : MAX_DEVICES-1;
}
// Go to next available device that meets the requiredFeatures
while((allDevices[curDevice] == NULL) || !(deviceHandler_getDeviceAvailable(allDevices[curDevice])) || !(allDevices[curDevice]->features & requiredFeatures)) {
if(allDevices[curDevice] != NULL && showAllDevices && (allDevices[curDevice]->features & requiredFeatures)) {
break; // Show all devices? then continue
}
curDevice += direction;
if((curDevice < 0) || (curDevice >= MAX_DEVICES)){
curDevice = direction > 0 ? 0 : MAX_DEVICES-1;
}
}
i+=direction;
if(i < 0) i = MAX_DEVICES;
else if (i > MAX_DEVICES) i = 0;
}

doBackdrop();
DrawEmptyBox(20,190, vmode->fbWidth-20, 410, COLOR_BLACK);
WriteFontStyled(640/2, 195, type == DEVICE_DEST ? "Destination Device" : "Device Selection", 1.0f, true, defaultColor);
Expand Down Expand Up @@ -1559,7 +1571,12 @@ void select_device(int type)
inAdvanced ^= 1;
if(btns & PAD_TRIGGER_Z) {
showAllDevices ^= 1;
direction = 0;
if(!showAllDevices && !deviceHandler_getDeviceAvailable(allDevices[curDevice])) {
direction = 1;
}
else {
direction = 0;
}
}
if(inAdvanced) {
if((btns & PAD_BUTTON_RIGHT) || (btns & PAD_BUTTON_LEFT)) {
Expand All @@ -1574,6 +1591,7 @@ void select_device(int type)
direction = -1;
}
}

if(btns & PAD_BUTTON_A) {
if(!inAdvanced) {
if(type == DEVICE_CUR)
Expand Down

0 comments on commit 2075d18

Please sign in to comment.