Fix the name stripping logic

This commit is contained in:
David Fowler 2015-11-01 03:39:56 -08:00
parent eaf05ea596
commit da2925e920
3 changed files with 13 additions and 9 deletions

View file

@ -3,7 +3,8 @@
#include "pal.h"
pal::string_t change_extension(const pal::string_t& filename, const pal::char_t* new_extension);
bool ends_with(const pal::string_t& value, const pal::string_t& suffix);
pal::string_t get_executable(const pal::string_t& filename);
pal::string_t get_directory(const pal::string_t& path);
pal::string_t get_filename(const pal::string_t& path);
void append_path(pal::string_t& path1, const pal::char_t* path2);

View file

@ -49,7 +49,8 @@ bool parse_arguments(const int argc, const pal::char_t* argv[], arguments_t& arg
// coreconsole mode. Find the managed app in the same directory
pal::string_t managed_app(own_dir);
managed_app.push_back(DIR_SEPARATOR);
managed_app.append(change_extension(own_name, _X(".dll")));
managed_app.append(get_executable(own_name));
managed_app.append(_X(".dll"));
args.managed_application = managed_app;
args.app_argv = &argv[1];
args.app_argc = argc - 1;

View file

@ -16,22 +16,24 @@ void append_path(pal::string_t& path1, const pal::char_t* path2)
}
}
pal::string_t change_extension(const pal::string_t& filename, const pal::char_t* new_extension)
pal::string_t get_executable(const pal::string_t& filename)
{
pal::string_t result(filename);
auto ext_sep = result.find_last_of('.');
if (ext_sep != pal::string_t::npos)
if (ends_with(result, _X(".exe")))
{
// We need to strip off the old extension
result.erase(ext_sep);
result.erase(result.length() - 4);
}
// Append the new extension
result.append(new_extension);
return result;
}
bool ends_with(const pal::string_t& value, const pal::string_t& suffix)
{
return (0 == value.compare(value.length() - suffix.length(), suffix.length(), suffix));
}
pal::string_t get_filename(const pal::string_t& path)
{
// Find the last dir separator