Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
4d453a83
Commit
4d453a83
authored
Apr 02, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fs/NarrowPath: add class FromNarrowPath
Move code from ParseCommandLine().
parent
61d7b436
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
12 deletions
+56
-12
CommandLine.cxx
src/CommandLine.cxx
+2
-12
NarrowPath.cxx
src/fs/NarrowPath.cxx
+19
-0
NarrowPath.hxx
src/fs/NarrowPath.hxx
+35
-0
No files found.
src/CommandLine.cxx
View file @
4d453a83
...
...
@@ -33,11 +33,11 @@
#include "playlist/PlaylistRegistry.hxx"
#include "playlist/PlaylistPlugin.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/NarrowPath.hxx"
#include "fs/Traits.hxx"
#include "fs/FileSystem.hxx"
#include "fs/StandardDirectory.hxx"
#include "system/Error.hxx"
#include "util/Macros.hxx"
#include "util/RuntimeError.hxx"
#include "util/Domain.hxx"
#include "util/OptionDef.hxx"
...
...
@@ -380,17 +380,7 @@ ParseCommandLine(int argc, char **argv, struct options &options,
if
(
config_file
!=
nullptr
)
{
/* use specified configuration file */
#ifdef _UNICODE
wchar_t
buffer
[
MAX_PATH
];
auto
result
=
MultiByteToWideChar
(
CP_ACP
,
0
,
config_file
,
-
1
,
buffer
,
ARRAY_SIZE
(
buffer
));
if
(
result
<=
0
)
throw
MakeLastError
(
"MultiByteToWideChar() failed"
);
ReadConfigFile
(
config
,
Path
::
FromFS
(
buffer
));
#else
ReadConfigFile
(
config
,
Path
::
FromFS
(
config_file
));
#endif
ReadConfigFile
(
config
,
FromNarrowPath
(
config_file
));
return
;
}
...
...
src/fs/NarrowPath.cxx
View file @
4d453a83
...
...
@@ -22,6 +22,8 @@
#ifdef _UNICODE
#include "lib/icu/Win32.hxx"
#include "system/Error.hxx"
#include "util/Macros.hxx"
#include <windows.h>
...
...
@@ -33,4 +35,21 @@ NarrowPath::NarrowPath(Path _path) noexcept
value
=
Value
::
Empty
();
}
static
AllocatedPath
AcpToAllocatedPath
(
const
char
*
s
)
{
wchar_t
buffer
[
MAX_PATH
];
auto
result
=
MultiByteToWideChar
(
CP_ACP
,
0
,
s
,
-
1
,
buffer
,
ARRAY_SIZE
(
buffer
));
if
(
result
<=
0
)
throw
MakeLastError
(
"MultiByteToWideChar() failed"
);
return
AllocatedPath
::
FromFS
(
buffer
);
}
FromNarrowPath
::
FromNarrowPath
(
const
char
*
s
)
:
value
(
AcpToAllocatedPath
(
s
))
{
}
#endif
/* _UNICODE */
src/fs/NarrowPath.hxx
View file @
4d453a83
...
...
@@ -23,6 +23,7 @@
#include "Path.hxx"
#ifdef _UNICODE
#include "AllocatedPath.hxx"
#include "util/AllocatedString.hxx"
#else
#include "util/StringPointer.hxx"
...
...
@@ -59,4 +60,38 @@ public:
}
};
/**
* A path name converted from a "narrow" string. This is used to
* import an existing narrow string to a #Path.
*/
class
FromNarrowPath
{
#ifdef _UNICODE
using
Value
=
AllocatedPath
;
#else
using
Value
=
Path
;
#endif
Value
value
{
nullptr
};
public
:
FromNarrowPath
()
=
default
;
#ifdef _UNICODE
/**
* Throws on error.
*/
FromNarrowPath
(
const
char
*
s
);
#else
constexpr
FromNarrowPath
(
const
char
*
s
)
noexcept
:
value
(
Value
::
FromFS
(
s
))
{}
#endif
#ifndef _UNICODE
constexpr
#endif
operator
Path
()
const
noexcept
{
return
value
;
}
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment