Rev 121 | Rev 187 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include <spk.h>using namespace System;using namespace Runtime::InteropServices;using namespace System::Drawing;#define CONNECTERROR_UNKNOWN -1enum {CONNECTERROR_NONE, CONNECTERROR_TIMEOUT, CONNECTERROR_NOFILE, CONNECTERROR_FAILED};inline Utils::String _S(System::String ^str){if ( !str || !str->Length )return "";const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(str)).ToPointer();std::string s = chars;Marshal::FreeHGlobal(IntPtr((void*)chars));return s;}inline CyString CyStringFromSystemString( System::String ^str){if ( !str || !str->Length )return NullString;const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(str)).ToPointer();std::string s = chars;// CyString *newStr = new CyString(chars);Marshal::FreeHGlobal(IntPtr((void*)chars));// return *newStr;return CyString(s);}inline int CheckWebFileExists(String ^url){int ret = CONNECTERROR_UNKNOWN;try{// check for the fileNet::WebRequest ^check = (Net::HttpWebRequest ^)Net::WebRequest::Create(url);check->Credentials = Net::CredentialCache::DefaultCredentials;Net::WebResponse ^response = (Net::HttpWebResponse ^)check->GetResponse();// check the file size__int64 fileSize = response->ContentLength;if ( fileSize )ret = CONNECTERROR_NONE;response->Close();}catch (System::Net::WebException ^ex){if ( ex->Status == System::Net::WebExceptionStatus::ConnectFailure )ret = CONNECTERROR_FAILED;else if(ex->Status == System::Net::WebExceptionStatus::ConnectionClosed && !ex->Response)ret = CONNECTERROR_FAILED;else{switch ( cli::safe_cast<Net::HttpWebResponse ^>(ex->Response)->StatusCode ){case Net::HttpStatusCode::NotFound:ret = CONNECTERROR_NOFILE;break;case Net::HttpStatusCode::RequestTimeout:ret = CONNECTERROR_TIMEOUT;break;default:ret = CONNECTERROR_UNKNOWN;}}}return ret;}inline String ^ReadDataFromWeb(String ^url){bool ret = false;String ^data;try{System::Net::WebClient ^Client = gcnew System::Net::WebClient();Client->Headers->Add( "user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" );System::IO::Stream ^strm = Client->OpenRead(url);System::IO::StreamReader ^sr = gcnew System::IO::StreamReader(strm);data = sr->ReadToEnd();strm->Close();sr->Close();}catch (System::Net::WebException ^){return nullptr;}if ( data && data->Length )return data;return nullptr;}inline System::String ^SystemStringFromCyString ( CyString str ){System::String ^Str = gcnew System::String(str.c_str());return Str;}inline System::String ^_US(const Utils::String &str){System::String ^Str = gcnew System::String(str.c_str());return Str;}inline System::Drawing::Bitmap ^LoadIcon(CBaseFile *p){Utils::String file = p->GetIcon()->filePointer();if (!file.empty()){file = file.findReplace("/", "\\").findReplace("\\\\", "\\");bool doIcon = false;System::String ^sFile = _US(file);if ( System::IO::File::Exists(sFile) ){Bitmap ^myBitmap = gcnew Bitmap(sFile);return myBitmap;}}return nullptr;}inline System::String ^GetProgramVersionString(float version, int beta){System::String ^str = "V" + SystemStringFromCyString(CyString::CreateFromFloat(version, 2));// beta versionif ( beta > 0 )str += " (Beta " + beta + ")";// RC releaseelse if ( beta < 0 )str += " (RC " + (0 - beta) + ")";return str;}