mirror of https://github.com/buggins/dlangui.git
refactor file operations
This commit is contained in:
parent
a682fd63bc
commit
f7409f6c07
|
@ -294,6 +294,7 @@
|
|||
<Folder name="core">
|
||||
<File path="src\dlangui\core\collections.d" />
|
||||
<File path="src\dlangui\core\events.d" />
|
||||
<File path="src\dlangui\core\files.d" />
|
||||
<File path="src\dlangui\core\i18n.d" />
|
||||
<File path="src\dlangui\core\linestream.d" />
|
||||
<File path="src\dlangui\core\logger.d" />
|
||||
|
|
|
@ -63,3 +63,4 @@ public import dlangui.widgets.tree;
|
|||
public import dlangui.widgets.combobox;
|
||||
public import dlangui.graphics.fonts;
|
||||
public import dlangui.core.i18n;
|
||||
public import dlangui.core.files;
|
||||
|
|
|
@ -58,6 +58,7 @@ module dlangui.core.i18n;
|
|||
|
||||
import dlangui.core.types;
|
||||
import dlangui.core.logger;
|
||||
import dlangui.core.files;
|
||||
private import dlangui.core.linestream;
|
||||
private import std.utf;
|
||||
private import std.algorithm;
|
||||
|
|
|
@ -390,82 +390,3 @@ dchar dcharToUpper(dchar ch) {
|
|||
return ch;
|
||||
}
|
||||
|
||||
version (Windows) {
|
||||
/// path delimiter (\ for windows, / for others)
|
||||
immutable char PATH_DELIMITER = '\\';
|
||||
} else {
|
||||
/// path delimiter (\ for windows, / for others)
|
||||
immutable char PATH_DELIMITER = '/';
|
||||
}
|
||||
|
||||
/** returns true if char ch is / or \ slash */
|
||||
bool isPathDelimiter(char ch) {
|
||||
return ch == '/' || ch == '\\';
|
||||
}
|
||||
|
||||
/** returns current executable path only, including last path delimiter */
|
||||
@property string exePath() {
|
||||
import std.file;
|
||||
string path = thisExePath();
|
||||
int lastSlash = 0;
|
||||
for (int i = 0; i < path.length; i++)
|
||||
if (path[i] == PATH_DELIMITER)
|
||||
lastSlash = i;
|
||||
return path[0 .. lastSlash + 1];
|
||||
}
|
||||
|
||||
/// converts path delimiters to standard for platform inplace in buffer(e.g. / to \ on windows, \ to / on posix), returns buf
|
||||
char[] convertPathDelimiters(char[] buf) {
|
||||
foreach(ref ch; buf) {
|
||||
version (Windows) {
|
||||
if (ch == '/')
|
||||
ch = '\\';
|
||||
} else {
|
||||
if (ch == '\\')
|
||||
ch = '/';
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
/** converts path delimiters to standard for platform (e.g. / to \ on windows, \ to / on posix) */
|
||||
string convertPathDelimiters(string src) {
|
||||
char[] buf = src.dup;
|
||||
return cast(string)convertPathDelimiters(buf);
|
||||
}
|
||||
|
||||
/** appends file path parts with proper delimiters e.g. appendPath("/home/user", ".myapp", "config") => "/home/user/.myapp/config" */
|
||||
string appendPath(string[] pathItems ...) {
|
||||
char[] buf;
|
||||
foreach (s; pathItems) {
|
||||
if (buf.length && !isPathDelimiter(buf[$-1]))
|
||||
buf ~= PATH_DELIMITER;
|
||||
buf ~= s;
|
||||
}
|
||||
return convertPathDelimiters(buf).dup;
|
||||
}
|
||||
|
||||
/** appends file path parts with proper delimiters (as well converts delimiters inside path to system) to buffer e.g. appendPath("/home/user", ".myapp", "config") => "/home/user/.myapp/config" */
|
||||
char[] appendPath(char[] buf, string[] pathItems ...) {
|
||||
foreach (s; pathItems) {
|
||||
if (buf.length && !isPathDelimiter(buf[$-1]))
|
||||
buf ~= PATH_DELIMITER;
|
||||
buf ~= s;
|
||||
}
|
||||
return convertPathDelimiters(buf);
|
||||
}
|
||||
|
||||
/** split path into elements, e.g. /home/user/dir1 -> ["home", "user", "dir1"], "c:\dir1\dir2" -> ["c:", "dir1", "dir2"] */
|
||||
string[] splitPath(string path) {
|
||||
string[] res;
|
||||
int start = 0;
|
||||
for (int i = 0; i <= path.length; i++) {
|
||||
char ch = i < path.length ? path[i] : 0;
|
||||
if (ch == '\\' || ch == '/' || ch == 0) {
|
||||
if (start < i)
|
||||
res ~= path[start .. i].dup;
|
||||
start = i + 1;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ module dlangui.dialogs.filedlg;
|
|||
import dlangui.core.events;
|
||||
import dlangui.core.i18n;
|
||||
import dlangui.core.stdaction;
|
||||
import dlangui.core.files;
|
||||
import dlangui.widgets.controls;
|
||||
import dlangui.widgets.lists;
|
||||
import dlangui.widgets.popup;
|
||||
|
|
|
@ -28,6 +28,7 @@ import std.file;
|
|||
|
||||
import dlangui.core.logger;
|
||||
import dlangui.core.events;
|
||||
import dlangui.core.files;
|
||||
import dlangui.graphics.drawbuf;
|
||||
import dlangui.graphics.fonts;
|
||||
import dlangui.graphics.ftfonts;
|
||||
|
|
|
@ -39,6 +39,7 @@ import dlangui.graphics.drawbuf;
|
|||
import dlangui.graphics.images;
|
||||
import dlangui.graphics.fonts;
|
||||
import dlangui.core.logger;
|
||||
import dlangui.core.files;
|
||||
|
||||
version (USE_OPENGL) {
|
||||
import dlangui.graphics.glsupport;
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue