Skip to content

Commit

Permalink
- patch for this note: 03d7602#commitcomment-81265953
Browse files Browse the repository at this point in the history
  • Loading branch information
madame-rachelle committed Aug 16, 2022
1 parent a9cadd3 commit ee13237
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/common/platform/win32/i_system.cpp
Expand Up @@ -66,6 +66,8 @@

#include <shellapi.h>

#include <direct.h>

#include "hardware.h"
#include "printf.h"

Expand Down Expand Up @@ -962,19 +964,33 @@ void I_SetThreadNumaNode(std::thread &thread, int numaNode)

void I_OpenShellFolder(const char* folder)
{
FString proc = folder;
proc.ReplaceChars('/', '\\');
Printf("Opening folder: %s\n", proc.GetChars());
proc.Format("\"%s\"", proc.GetChars());
ShellExecuteW(NULL, L"open", L"explorer.exe", proc.WideString().c_str(), NULL, SW_SHOWNORMAL);
char curdir[256];
if (!getcwd (curdir, countof(curdir)))
{
Printf ("Current path too long\n");
return;
}

chdir(folder);
Printf("Opening folder: %s\n", folder);
std::system("explorer .");
chdir(curdir);
}

void I_OpenShellFile(const char* file)
{
FString proc = file;
proc.ReplaceChars('/', '\\');
Printf("Opening folder to file: %s\n", proc.GetChars());
proc.Format("/select,\"%s\"", proc.GetChars());
ShellExecuteW(NULL, L"open", L"explorer.exe", proc.WideString().c_str(), NULL, SW_SHOWNORMAL);
char curdir[256];
if (!getcwd (curdir, countof(curdir)))
{
Printf ("Current path too long\n");
return;
}

std::string folder = file;
folder.erase(folder.find_last_of('/'), std::string::npos);
chdir(folder.c_str());
Printf("Opening folder: %s\n", folder.c_str());
std::system("explorer .");
chdir(curdir);
}

4 comments on commit ee13237

@coelckers
Copy link
Member

@coelckers coelckers commented on ee13237 Aug 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code may not work with international character sets! The CRT's functions are not Unicode aware. Better use the wide versions of these functions or the Win32 'W'-style system calls directly for Unicode-safe path handling.

@madame-rachelle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have to be changed in the "dir" function in c_engine.cpp too then, because it works exactly the same way.

@madame-rachelle
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I will take a look at it.

@coelckers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will have to be changed in the "dir" function in c_engine.cpp too then, because it works exactly the same way.

No idea, it's something I never used. Of course that needs changing, too, then.

Please sign in to comment.