tahoma2d/toonz/sources/toonzfarm/tfarmclient/util.cpp

46 lines
1.1 KiB
C++
Raw Normal View History

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