@@ -51,13 +51,52 @@ CConnectionInstance::CConnectionInstance(const std::string& sProtobufDefinition,
51
51
throw ELibGRPCWrapperInterfaceException (LIBGRPCWRAPPER_ERROR_COULDNOTCREATECHANNEL, " Could not create channel: " + sEndPoint );
52
52
53
53
// Create temporary.proto file and fill with given content
54
- const std::string sProtoFilePathTemp = " temp.proto" ;
55
- std::ofstream tempFile (sProtoFilePathTemp );
54
+ // TODO: Make virtual path readers!!!
55
+ std::wstring sMapPathW ;
56
+ std::string sMapPath ;
57
+ #ifdef _WIN32
58
+ std::vector<wchar_t > TempPathBufferW;
59
+ TempPathBufferW.resize (MAX_PATH + 1 );
60
+ auto nSize = GetTempPathW (MAX_PATH, TempPathBufferW.data ());
61
+ if (nSize == 0 )
62
+ throw ELibGRPCWrapperInterfaceException (LIBGRPCWRAPPER_ERROR_COULDNOTRETRIEVETEMPPATHS);
63
+
64
+ TempPathBufferW[MAX_PATH] = 0 ;
65
+ sMapPathW = TempPathBufferW.data ();
66
+
67
+ std::vector<char > TempPathBuffer (MAX_PATH * 2 + 4 );
68
+ int nResult = WideCharToMultiByte (CP_UTF8, 0 , sMapPathW .c_str (), sMapPathW .size (), TempPathBuffer.data (), MAX_PATH, nullptr , nullptr );
69
+ if (nResult == 0 )
70
+ throw ELibGRPCWrapperInterfaceException (LIBGRPCWRAPPER_ERROR_COULDNOTCONVERTUNICODESTRING);
71
+
72
+ TempPathBuffer.at (TempPathBuffer.size () - 1 ) = 0 ;
73
+
74
+ sMapPath = TempPathBuffer.data ();
75
+
76
+ #else
77
+ sMapPath = " /tmp" ;
78
+ #endif
79
+
80
+ std::string sProtoFilePathTemp = " libgrpc_temp_" ;
81
+
82
+ for (int index = 0 ; index < 16 ; index ++) {
83
+ uint8_t nValue = rand () % 16 ;
84
+ if (nValue < 10 )
85
+ sProtoFilePathTemp += (' 0' + nValue);
86
+ else
87
+ sProtoFilePathTemp += (' a' + nValue - 10 );
88
+ }
89
+
90
+ sProtoFilePathTemp += " .proto" ;
91
+
92
+ std::wstring sProtoFilePathTempW (sProtoFilePathTemp .begin (), sProtoFilePathTemp .end ());
93
+
94
+ std::ofstream tempFile (sMapPathW + L" /" + sProtoFilePathTempW );
56
95
tempFile << sProtobufDefinition ;
57
96
tempFile.close ();
58
97
59
98
m_pSourceTree = std::make_shared<google::protobuf::compiler::DiskSourceTree>();
60
- m_pSourceTree->MapPath (" " , " W:/libgrpc/build/Release " );
99
+ m_pSourceTree->MapPath (" " , sMapPath );
61
100
62
101
m_pErrorCollector = std::make_shared<CConnectionErrorCollector> ();
63
102
0 commit comments