Skip to content

Commit

Permalink
Rebase: Make archive detection more robust and add it to the CLI (mel…
Browse files Browse the repository at this point in the history
…onDS-emu#1560)

* Rebase/recreate my changes and add MIME support

This commit recreates the changes proposed in melonDS-emu#1394 on top of the
current master (b069a2a).
This also adds support for determining filetypes using the MIME database
provided by `QMimeDatabase`.

* Move member syntax warning to a more appropriate place

* Deduplicate member syntax warning

* Change warning from "vertical bars" to "|"

* Conform brace placement to coding style

* Fix QFileDialog filter when ArchiveExtensions is empty

* Final cleanup and fixes

- Changes the NDS and GBA ROM MIME-Type constants to QStrings.
- Removes a leftover warning message.
- Uses Type() syntax instead of Type{} syntax for temporaries.

* Explain the origin of the supported archive list

Co-authored-by: Jan Felix Langenbach <[email protected]>
  • Loading branch information
Janfel and Jan Felix Langenbach authored Jan 17, 2023
1 parent d83172e commit 3e02d3f
Show file tree
Hide file tree
Showing 4 changed files with 290 additions and 148 deletions.
46 changes: 13 additions & 33 deletions src/frontend/qt_sdl/CLI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CommandLineOptions* ManageArgs(QApplication& melon)

parser.addOption(QCommandLineOption({"b", "boot"}, "Whether to boot firmware on startup. Defaults to \"auto\" (boot if NDS rom given)", "auto/always/never", "auto"));
parser.addOption(QCommandLineOption({"f", "fullscreen"}, "Start melonDS in fullscreen mode"));

#ifdef ARCHIVE_SUPPORT_ENABLED
parser.addOption(QCommandLineOption({"a", "archive-file"}, "Specify file to load inside an archive given (NDS)", "rom"));
parser.addOption(QCommandLineOption({"A", "archive-file-gba"}, "Specify file to load inside an archive given (GBA)", "rom"));
Expand All @@ -50,25 +50,25 @@ CommandLineOptions* ManageArgs(QApplication& melon)
CommandLineOptions* options = new CommandLineOptions;

options->fullscreen = parser.isSet("fullscreen");

QStringList posargs = parser.positionalArguments();
switch (posargs.size())
{
default:
printf("Too many positional arguments; ignoring 3 onwards\n");
case 2:
options->gbaRomPath = QStringList(posargs[1]);
options->gbaRomPath = posargs[1];
case 1:
options->dsRomPath = QStringList(posargs[0]);
options->dsRomPath = posargs[0];
case 0:
break;
}

QString bootMode = parser.value("boot");
if (bootMode == "auto")
{
options->boot = posargs.size() > 0;
}
options->boot = !posargs.empty();
}
else if (bootMode == "always")
{
options->boot = true;
Expand All @@ -86,50 +86,30 @@ CommandLineOptions* ManageArgs(QApplication& melon)
#ifdef ARCHIVE_SUPPORT_ENABLED
if (parser.isSet("archive-file"))
{
if (options->dsRomPath.isEmpty())
if (options->dsRomPath.has_value())
{
options->errorsToDisplay += "Option -a/--archive-file given, but no archive specified!";
options->dsRomArchivePath = parser.value("archive-file");
}
else
{
options->dsRomPath += parser.value("archive-file");
}
}
else if (!options->dsRomPath.isEmpty())
{
//TODO-CLI: try to automatically find ROM
QStringList paths = options->dsRomPath[0].split("|");
if (paths.size() >= 2)
{
printf("Warning: use the a.zip|b.nds format at your own risk!\n");
options->dsRomPath = paths;
options->errorsToDisplay += "Option -a/--archive-file given, but no archive specified!";
}
}

if (parser.isSet("archive-file-gba"))
{
if (options->gbaRomPath.isEmpty())
if (options->gbaRomPath.has_value())
{
options->errorsToDisplay += "Option -A/--archive-file-gba given, but no archive specified!";
options->gbaRomArchivePath = parser.value("archive-file-gba");
}
else
{
options->gbaRomPath += parser.value("archive-file-gba");
}
}
else if (!options->gbaRomPath.isEmpty())
{
//TODO-CLI: try to automatically find ROM
QStringList paths = options->gbaRomPath[0].split("|");
if (paths.size() >= 2)
{
printf("Warning: use the a.zip|b.gba format at your own risk!\n");
options->gbaRomPath = paths;
options->errorsToDisplay += "Option -A/--archive-file-gba given, but no archive specified!";
}
}
#endif

return options;
}

}
}
10 changes: 7 additions & 3 deletions src/frontend/qt_sdl/CLI.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
melonDS 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 for more details.
You should have received a copy of the GNU General Public License along
with melonDS. If not, see http://www.gnu.org/licenses/.
*/
Expand All @@ -22,14 +22,18 @@
#include <QApplication>
#include <QStringList>

#include <optional>

namespace CLI {

struct CommandLineOptions
{
QStringList errorsToDisplay = {};

QStringList dsRomPath;
QStringList gbaRomPath;
std::optional<QString> dsRomPath;
std::optional<QString> dsRomArchivePath;
std::optional<QString> gbaRomPath;
std::optional<QString> gbaRomArchivePath;
bool fullscreen;
bool boot;
};
Expand Down
Loading

0 comments on commit 3e02d3f

Please sign in to comment.