mirror of
https://github.com/RubyMetric/chsrc.git
synced 2025-01-22 08:46:15 +08:00
Extract xy_unix_path_to_win()
This commit is contained in:
parent
ce309b6c8d
commit
b92c68ebed
5
chsrc.h
5
chsrc.h
|
@ -290,10 +290,7 @@ chsrc_check_file (const char* path)
|
|||
{
|
||||
char* cmd = NULL;
|
||||
if(xy_on_windows) {
|
||||
if (xy_str_start_with(path, "~/")){
|
||||
path = xy_2strjoin("%USERPROFILE%\\", xy_str_delete_prefix(path, "~/"));
|
||||
path = xy_str_gsub(path, "/", "\\");
|
||||
}
|
||||
path = xy_unix_path_to_win (path);
|
||||
cmd = xy_2strjoin ("type ", path);
|
||||
} else {
|
||||
cmd = xy_2strjoin ("cat ", path);
|
||||
|
|
17
xy.h
17
xy.h
|
@ -507,7 +507,7 @@ _xy_win_powershell_profile ()
|
|||
}
|
||||
|
||||
char*
|
||||
_xy_win_powershellv5_profile()
|
||||
_xy_win_powershellv5_profile ()
|
||||
{
|
||||
return xy_2strjoin(xy_os_home, "\\Documents\\WindowsPowerShell\\Microsoft.PowerShell_profile.ps1");
|
||||
}
|
||||
|
@ -517,7 +517,7 @@ _xy_win_powershellv5_profile()
|
|||
* @note Windows上,`path` 不要夹带变量名,因为最终 access() 不会帮你转换
|
||||
*/
|
||||
static bool
|
||||
xy_file_exist(char* path)
|
||||
xy_file_exist (char* path)
|
||||
{
|
||||
char* newpath = path;
|
||||
if (xy_on_windows)
|
||||
|
@ -529,4 +529,17 @@ xy_file_exist(char* path)
|
|||
return access(newpath, 0) ? false : true;
|
||||
}
|
||||
|
||||
|
||||
static const char*
|
||||
xy_unix_path_to_win (const char* path)
|
||||
{
|
||||
path = xy_str_strip(path); // 防止开发者多写了空格
|
||||
if (xy_str_start_with(path, "~/")){
|
||||
// 或 %USERPROFILE%
|
||||
path = xy_strjoin(3, xy_os_home, "\\", xy_str_delete_prefix(path, "~/"));
|
||||
path = xy_str_gsub(path, "/", "\\");
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue
Block a user