1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

Checking validity of a filepath

Discussion in 'Modding Help' started by ShnitzelKiller, Apr 26, 2015.

  1. ShnitzelKiller

    ShnitzelKiller Haxor

    Messages:
    590
    Is there a function I can use to check that a file exists, given a filepath as input?
    What I'm trying to do is check that a sound file exists. With images, you could check the dimensions or something to check that it loaded properly, but with sounds, I know of no corresponding object in KAG that can be manipulated. Only a playSound() function that takes a sound filepath directly as an argument. If it doesn't find the file, it just doesn't play a sound, but I want to check this beforehand.
     
  2. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Code:
    bool isFileValid(string file)
    {
    CFileMatcher matcher("myaudiofile.ogg");
    if (matcher.getFirst() != "") return true;
    else return false;
    }
    
    Maybe will that work? I've never used file matchers but I guess it works like that.
     
  3. ShnitzelKiller

    ShnitzelKiller Haxor

    Messages:
    590
    As it turned out, CFilematcher returns the nearest match in the whole Base directory for a given path or filename. So I had to first search, then require that the result is exactly equal to the input (or it could be some near approximation turning up a false positive). Is there any place to find documentations for all the functions in manual/functions.txt and objects.txt?
     
  4. Skinney

    Skinney THD Team THD Team Forum Moderator Tester

    Messages:
    468
    The only documentation available can be found here or searched with Belagerung in #kag.modding IRC.
     
  5. Asu

    Asu THD Team THD Team Forum Moderator

    Messages:
    1,580
    Maybe try my solution without the ".ogg" and check if the result has the ".ogg" within. This won't work with extensionless files though.