<commit_before>#include <string>
#include <memory>

#include <ShlObj.h>

#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_utils.hpp"

#include "WwiseSettingsReader.h"
#include "config.h"
#include "WAAPIHelpers.h"

bool GetWaapiSettings(int &waapiEnabled, int &waapiPort)
{
    fs::path wwiseSettingsPath;

#ifdef _WIN32
    PWSTR appDataPath;
    if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, NULL, &appDataPath) != S_OK)
    {
        return false;
    }
    wwiseSettingsPath = appDataPath;
    CoTaskMemFree(appDataPath);
    wwiseSettingsPath.append("Audiokinetic/Wwise/Wwise.wsettings");

    //check if wwise settings file is valid
    if (!fs::is_regular_file(wwiseSettingsPath))
    {
        return false;
    }

#else
    static_assert(false, "OSX not implemented for parsing wwise settings file.");
#endif

    //rapidxml can throw
    try
    {
        rapidxml::xml_document<char> wwiseSettingsXML;

        rapidxml::file<char> xmlFile(wwiseSettingsPath.generic_string().c_str());
        wwiseSettingsXML.parse<rapidxml::parse_default>(xmlFile.data());

        bool foundPropertyList = false;
        auto *propertyListNode = wwiseSettingsXML.first_node();

        //get property list
        while (propertyListNode)
        {
            if (!strcmp(propertyListNode->name(), "PropertyList"))
            {
                foundPropertyList = true;
                break;
            }
            propertyListNode = propertyListNode->first_node();
        }

        if (!foundPropertyList)
        {
            return false;
        }

        //find properties
        rapidxml::xml_node<char> *waapiEnabledNode  = nullptr;
        rapidxml::xml_node<char> *waapiPortNode     = nullptr;

        auto propertiesIter = propertyListNode->first_node();

        while (propertiesIter)
        {
            auto nameValue = propertiesIter->first_attribute("Name")->value();
            if (!strcmp(nameValue, "Waapi\\EnableWaapi"))
            {
                waapiEnabledNode = propertiesIter;
            }
            else if (!strcmp(nameValue, "Waapi\\WampPort"))
            {
                waapiPortNode = propertiesIter;
            }

            //found both
            if (waapiEnabledNode && waapiPortNode)
            {
                break;
            }

            propertiesIter = propertiesIter->next_sibling();
        }

        //set output variables
        if (waapiPortNode)
        {
            auto attrib = waapiPortNode->last_attribute("Value");
            if (attrib)
            {
                waapiPort = std::stoi(attrib->value());
            }
            else
            {
                waapiPort = -1;
            }
        }
        else
        {
            waapiPort = -1;
        }

        if (waapiEnabledNode)
        {
            auto attrib = waapiEnabledNode->last_attribute("Value");
            if (attrib)
            {
                char *val = attrib->value();
                waapiEnabled = strcmp(val, "True") == 0 ? 1 : 0;
            }
            else
            {
                waapiEnabled = -1;
            }
        }
        else
        {
            waapiEnabled = -1;
        }
    }
    catch (rapidxml::parse_error const& _e)
    {
		ignore(_e);
        return false;
    }

    return true;
}<commit_msg>Commit old fix for crash when parsing wwise xml.<commit_after>#include <string>
#include <memory>

#include <ShlObj.h>

#include "rapidxml/rapidxml.hpp"
#include "rapidxml/rapidxml_utils.hpp"

#include "WwiseSettingsReader.h"
#include "config.h"
#include "WAAPIHelpers.h"

bool GetWaapiSettings(int &waapiEnabled, int &waapiPort)
{
    fs::path wwiseSettingsPath;

#ifdef _WIN32
    PWSTR appDataPath;
    if (SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, NULL, &appDataPath) != S_OK)
    {
        return false;
    }
    wwiseSettingsPath = appDataPath;
    CoTaskMemFree(appDataPath);
    wwiseSettingsPath.append("Audiokinetic/Wwise/Wwise.wsettings");

    //check if wwise settings file is valid
    if (!fs::is_regular_file(wwiseSettingsPath))
    {
        return false;
    }

#else
    static_assert(false, "OSX not implemented for parsing wwise settings file.");
#endif

    //rapidxml can throw
    try
    {
        rapidxml::xml_document<char> wwiseSettingsXML;

        rapidxml::file<char> xmlFile(wwiseSettingsPath.generic_string().c_str());
        wwiseSettingsXML.parse<rapidxml::parse_default>(xmlFile.data());

        bool foundPropertyList = false;
        auto *propertyListNode = wwiseSettingsXML.first_node();

        //get property list
        while (propertyListNode)
        {
            if (!strcmp(propertyListNode->name(), "PropertyList"))
            {
                foundPropertyList = true;
                break;
            }
            propertyListNode = propertyListNode->first_node();
        }

        if (!foundPropertyList)
        {
            return false;
        }

        //find properties
        rapidxml::xml_node<char> *waapiEnabledNode  = nullptr;
        rapidxml::xml_node<char> *waapiPortNode     = nullptr;

        auto propertiesIter = propertyListNode->first_node();

        while (propertiesIter)
        {
            auto nameValue = propertiesIter->first_attribute("Name")->value();
            if (!strcmp(nameValue, "Waapi\\EnableWaapi"))
            {
                waapiEnabledNode = propertiesIter;
            }
            else if (!strcmp(nameValue, "Waapi\\WampPort"))
            {
                waapiPortNode = propertiesIter;
            }

            //found both
            if (waapiEnabledNode && waapiPortNode)
            {
                break;
            }

            propertiesIter = propertiesIter->next_sibling();
        }

        //set output variables
        if (waapiPortNode)
        {
            auto attrib = waapiPortNode->last_attribute("Value");
            if (attrib)
            {
                waapiPort = std::stoi(attrib->value());
            }
            else
            {
                waapiPort = -1;
            }
        }
        else
        {
            waapiPort = -1;
        }

        if (waapiEnabledNode)
        {
            auto attrib = waapiEnabledNode->last_attribute("Value");
            if (attrib)
            {
                char *val = attrib->value();
                waapiEnabled = strcmp(val, "True") == 0 ? 1 : 0;
            }
            else
            {
                waapiEnabled = -1;
            }
        }
        else
        {
            waapiEnabled = -1;
        }
    }
    catch (...)
    {
        return false;
    }

    return true;
}
{'fraction_non_alphanumeric': 0.10321615557217652, 'fraction_numerical': 0.002692595362752431, 'mean_word_length': 1.693795326349718, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 32}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5909277', 'n_tokens_mistral': 1969, 'n_tokens_neox': 1902, 'n_words': 358}