Fledge68 / WiiFlow_Lite

My mod of the Wii USB Loader WiiFlow
470 stars 58 forks source link

Accept any file ending for filetypes #277

Closed eku closed 3 years ago

eku commented 3 years ago

With this change WiiFlow accepts any string in filetypes as a file type. The file extension no longer has to contain a dot (and not more). Any text is allowed.

If you do not change your configuration of filetypes, you will not notice any change in behaviour. However, those who make use of this can solve the problem from #274 as follows.

Let's imagine we have PS1 games that are typically named like this:

Tales of Destiny II (USA) (Disc 1).cue
Tales of Destiny II (USA) (Disc 1) (Track 1).bin
Tales of Destiny II (USA) (Disc 1) (Track 2).bin
Tales of Destiny II (USA) (Disc 2).cue
Tales of Destiny II (USA) (Disc 2) (Track 1).bin
Tales of Destiny II (USA) (Disc 2) (Track 2).bin
Tales of Destiny II (USA) (Disc 3).cue
Tales of Destiny II (USA) (Disc 3) (Track 1).bin
Tales of Destiny II (USA) (Disc 3) (Track 2).bin

Then you would write either (Disc 1) (Track 1).bin in filetypes to select exactly the first bin of the first disc, or (Disc 1).cue to select the cue. For games that do not consist of multiple tracks per disc, you would write (Disc 1).bin in filetype. Combined, this gives filetypes=(Disc 1) (Track 1).bin|(Disc 1).bin.

The downside of the solution is that single-disc games must also follow the naming scheme.

Never mind, you don't have to use it. With the change, everything works as before, without changes to the configuration.

Fledge68 commented 3 years ago

i am not familiar with end_with() is it case sensitive? and IsFileSupported(const char *File, const vector& FileTypes) is also used to check the folder name for gamecube games that are exrtracted. so its used to see if the folder name is 'root'. does your changes cause an issue with this?

eku commented 3 years ago

is it case sensitive?

Yes it is. The updated implementation has been tested for case insensitivity and GC compatibility.

You may verify the function with the following test program

#include <iostream>
#include <string>

static inline bool IsFileSupported(const char *File, const char *FileType)
{
  auto fileName = std::string(File);
  auto fileType = std::string(FileType);

  if (fileName.length() >= fileType.length()) 
  {  
     return std::equal(fileName.end() - fileType.length(),
                       fileName.end(),
                       fileType.begin(),
                       [](const char & c1, const char & c2)
                       {     
                         return (c1 == c2 ||   
                                 std::toupper(c1) ==
                                 std::toupper(c2));
                       });
  }
  return false;
}

int main(int argc, char *argv[])
{
  if (argc < 3)
  {
    std::cerr << "usage: " << argv[0] << " filename filetype\n";
    return 1;
  }

  auto match = IsFileSupported(argv[1], argv[2]);
  if (match)
    std::cout << argv[1] << " ends with " << argv[2] << "\n";
  else
    std::cout << argv[1] << " ends not with " << argv[2] << "\n";

  return 0;
}
eku commented 3 years ago

Is there anything I can do to get the PR accepted?

Fledge68 commented 3 years ago

i thought you said you were going to do it wiimpathy's way using regex?

eku commented 3 years ago

i thought you said you were going to do it wiimpathy's way using regex?

Yes and no. I am preparing a PR for sorting out files via regex.

The change here does not have to be used for sorting out. In principle, this PR eliminates a restriction of file types to the dot three_character known from DOS times.

eku commented 3 years ago

Thanks for merging.