Re: Convert path to file system path on windows

2018-06-30 Thread Dr.No via Digitalmars-d-learn

Thank you very much u all guys.


Re: Convert path to file system path on windows

2018-06-21 Thread FreeSlave via Digitalmars-d-learn

On Thursday, 21 June 2018 at 18:46:05 UTC, Dr.No wrote:

How can I do that with D?

In C# you can do that:

var filename = @"C:\path\to\my\file.txt";
var file = new Uri(filename).AbsoluteUri;
// file is "file:///C:/path/to/my/file.txt"

How can I do that in D?


import std.stdio;
import std.exception;
import core.sys.windows.windows;
import std.windows.syserror;

@safe void henforce(HRESULT hres, lazy string msg = null, string 
file = __FILE__, size_t line = __LINE__)

{
if (hres != S_OK)
throw new WindowsException(hres, msg, file, line);
}

@trusted wstring absoluteUri(string path)
{
import std.path : absolutePath;
import std.utf : toUTF16z;
import core.sys.windows.shlwapi;
import core.sys.windows.wininet;

auto shlwapi = wenforce(LoadLibraryA("Shlwapi"), "Failed to 
load shlwapi");

enforce(shlwapi !is null);
auto urlCreateFromPath = 
cast(typeof())wenforce(shlwapi.GetProcAddress("UrlCreateFromPathW"), "Failed to find UrlCreateFromPathW");

scope(exit) FreeLibrary(shlwapi);
wchar[INTERNET_MAX_URL_LENGTH] buf;
auto size = cast(DWORD)buf.length;
henforce(urlCreateFromPath(path.absolutePath.toUTF16z, 
buf.ptr, , 0));

return buf[0..size].idup;
}

int main(string[] args)
{
foreach(path; args)
{
writeln(absoluteUri(path));
}
return 0;
}



Re: Convert path to file system path on windows

2018-06-21 Thread Timoses via Digitalmars-d-learn

On Thursday, 21 June 2018 at 18:46:05 UTC, Dr.No wrote:

How can I do that with D?

In C# you can do that:

var filename = @"C:\path\to\my\file.txt";
var file = new Uri(filename).AbsoluteUri;
// file is "file:///C:/path/to/my/file.txt"

How can I do that in D?


I don't know of a specific implementation that does the same, but 
I can point you to some spots you might look into:


std.path: https://dlang.org/phobos/std_path.html
std.uri: https://dlang.org/phobos/std_uri.html

vibe.inet.url: http://vibed.org/api/vibe.inet.url/URL
vibe.core.path: http://vibed.org/api/vibe.core.path/


I really feel like vibed's documentation api site is missing some 
nice examples of usage to get a quick feel of the provided api.


Convert path to file system path on windows

2018-06-21 Thread Dr.No via Digitalmars-d-learn

How can I do that with D?

In C# you can do that:

var filename = @"C:\path\to\my\file.txt";
var file = new Uri(filename).AbsoluteUri;
// file is "file:///C:/path/to/my/file.txt"

How can I do that in D?