Skarsnik / QUsb2snes

A Qt based webserver for usb2snes. Users: go check usb2snes.com
https://skarsnik.github.io/QUsb2snes/
GNU General Public License v3.0
52 stars 34 forks source link

Making tweaks to SendToSd2snes #59

Open codemann8 opened 4 years ago

codemann8 commented 4 years ago

I've managed to figure out the necessary steps to get SendToSd2snes to compile to .exe, which is good. However, I'm running into an issue where file IO operations are infinitely freezing. If I had to guess, it might be due to file IO operations happening back to back, but I have no clue.

So far, I've only modified transfertFile() method, here is what I modified it to:

void SendToDialog::transfertFile()
{
    QFile fi(fileInfos.absoluteFilePath());
    qDebug() << "Opening file" << fi.open(QIODevice::ReadOnly);
    QByteArray data = fi.readAll();
    sendingFile = true;
    // 6 mb take 60 sec
    int sizeInMb = 1;
    if (data.size() > 1024 * 1024)
        sizeInMb = (data.size() / (1024 * 1024)) + 0.5;
    bool replaceFile = false;
    if (fileInfos.fileName().endsWith(".sfc") && usb2snes->getFile(ui->dirLineEdit->text() + "/alttp_msu.sfc") > 0)
    {
        setStatusLabel("Deleting old ROM");
        usb2snes->deleteFile(ui->dirLineEdit->text() + "/alttp_msu.sfc");
        replaceFile = true;
    }
    setStatusLabel(tr("Transferring file - Estimated time is %1 seconds").arg(sizeInMb * 10));
    progressStep = 80 / (sizeInMb * 10);

    if (replaceFile)
    {
        usb2snes->sendFile(ui->dirLineEdit->text() + "/alttp_msu.sfc", data);
    }
    else
    {
        usb2snes->sendFile(ui->dirLineEdit->text() + "/" + fileInfos.fileName(), data);
    }
}

Essentially what I'm trying to do is if the file getting transferred is a ROM file AND a specific pre-determined ROM filename already exists. I want it to delete this old ROM file and replace it with another new ROM. This is particularly a desirable feature when running randomizer games with MSU-1 where the ROM file must have the same prefix. I'm hoping you might be able to quickly see any problems with the above code, as I'm no expert in Qt dev nor these usb2snes libraries. Also, this might even be made simpler if overwriting files worked in SendToSd2snes, but as it currently is, it does not.

Skarsnik commented 4 years ago

Does the the file transfert block when using it normally?

codemann8 commented 4 years ago

@Skarsnik No, the transfer works when the code is back to its original form.

But also I should be clear, overwriting a file that already exists has never worked with this program, in fact it has always caused the program to inifinitely "try" to transfer, and the only remedy it to force close Qusb2Snes AND power down my SNES console and turn back on.

codemann8 commented 4 years ago

@Skarsnik

Skarsnik commented 4 years ago

Interesting, I need to look more into this, I don't remember if the firmware allows to just overwrite x)

codemann8 commented 4 years ago

@Skarsnik Any ideas on what I could change in my code to make this work? I don't seem to know why the first IO operation (the check if file exists) is successful and everything after freezes.