Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#include "util.h"
Toshihiro Shimizu 890ddd
#include "tfilepath.h"
Toshihiro Shimizu 890ddd
#include "texception.h"
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
#include <windows.h></windows.h>
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
string convertToUncString(const TFilePath &fp)
Toshihiro Shimizu 890ddd
{
Toshihiro Shimizu 890ddd
#ifdef WIN32
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DWORD cbBuff = 1024; // Size of Buffer
Toshihiro Shimizu 890ddd
	char szBuff[1024];   // Buffer to receive information
Toshihiro Shimizu 890ddd
	REMOTE_NAME_INFO *prni = (REMOTE_NAME_INFO *)&szBuff;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	// Pointers to head of buffer
Toshihiro Shimizu 890ddd
	UNIVERSAL_NAME_INFO *puni = (UNIVERSAL_NAME_INFO *)&szBuff;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	DWORD dwResult = WNetGetUniversalName(toString(fp.getWideString()).c_str(),
Toshihiro Shimizu 890ddd
										  UNIVERSAL_NAME_INFO_LEVEL,
Toshihiro Shimizu 890ddd
										  (LPVOID)&szBuff,
Toshihiro Shimizu 890ddd
										  &cbBuff);
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	switch (dwResult) {
Toshihiro Shimizu 890ddd
	case NO_ERROR:
Toshihiro Shimizu 890ddd
		return puni->lpUniversalName;
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	case ERROR_NOT_CONNECTED:
Toshihiro Shimizu 890ddd
		// The network connection does not exists.
Toshihiro Shimizu 890ddd
		throw TException("The path specified doesn't refer to a shared folder");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	case ERROR_CONNECTION_UNAVAIL:
Toshihiro Shimizu 890ddd
		// The device is not currently connected,
Toshihiro Shimizu 890ddd
		// but it is a persistent connection.
Toshihiro Shimizu 890ddd
		throw TException("The shared folder is not currently connected");
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
	default:
Toshihiro Shimizu 890ddd
		throw TException("Cannot convert the path specified to UNC");
Toshihiro Shimizu 890ddd
	}
Toshihiro Shimizu 890ddd
Toshihiro Shimizu 890ddd
#else
Toshihiro Shimizu 890ddd
	return fp.getFullPath().c_str();
Toshihiro Shimizu 890ddd
#endif
Toshihiro Shimizu 890ddd
}