| 1 | 
           cycrow | 
           1 | 
           #include <spk.h>
  | 
        
        
            | 
            | 
           2 | 
              | 
        
        
            | 
            | 
           3 | 
           using namespace System;
  | 
        
        
            | 
            | 
           4 | 
           using namespace Runtime::InteropServices;
  | 
        
        
            | 
            | 
           5 | 
           using namespace System::Drawing;
  | 
        
        
            | 
            | 
           6 | 
              | 
        
        
            | 
            | 
           7 | 
           #define CONNECTERROR_UNKNOWN	-1
  | 
        
        
            | 
            | 
           8 | 
           enum {CONNECTERROR_NONE, CONNECTERROR_TIMEOUT, CONNECTERROR_NOFILE, CONNECTERROR_FAILED};
  | 
        
        
            | 
            | 
           9 | 
              | 
        
        
           | 39 | 
           cycrow | 
           10 | 
           inline Utils::String _S(System::String ^str)
  | 
        
        
            | 
            | 
           11 | 
           {
  | 
        
        
            | 
            | 
           12 | 
           	if ( !str || !str->Length )
  | 
        
        
            | 
            | 
           13 | 
           		return "";
  | 
        
        
            | 
            | 
           14 | 
           	const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(str)).ToPointer();
  | 
        
        
            | 
            | 
           15 | 
           	std::string s = chars;
  | 
        
        
            | 
            | 
           16 | 
           	Marshal::FreeHGlobal(IntPtr((void*)chars));
  | 
        
        
            | 
            | 
           17 | 
           	return s;
  | 
        
        
            | 
            | 
           18 | 
           }
  | 
        
        
           | 1 | 
           cycrow | 
           19 | 
           inline CyString CyStringFromSystemString( System::String ^str)
  | 
        
        
            | 
            | 
           20 | 
           {
  | 
        
        
            | 
            | 
           21 | 
           	if ( !str || !str->Length )
  | 
        
        
            | 
            | 
           22 | 
           		return NullString;
  | 
        
        
            | 
            | 
           23 | 
           	const char* chars = (const char*)(Marshal::StringToHGlobalAnsi(str)).ToPointer();
  | 
        
        
            | 
            | 
           24 | 
           	std::string s = chars;
  | 
        
        
            | 
            | 
           25 | 
           //	CyString *newStr = new CyString(chars);
  | 
        
        
            | 
            | 
           26 | 
           	Marshal::FreeHGlobal(IntPtr((void*)chars));
  | 
        
        
            | 
            | 
           27 | 
           //	return *newStr;
  | 
        
        
            | 
            | 
           28 | 
           	return CyString(s);
  | 
        
        
            | 
            | 
           29 | 
           }
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
            | 
            | 
           31 | 
           inline int CheckWebFileExists(String ^url)
  | 
        
        
            | 
            | 
           32 | 
           {
  | 
        
        
            | 
            | 
           33 | 
           	int ret = CONNECTERROR_UNKNOWN;
  | 
        
        
            | 
            | 
           34 | 
           	try 
  | 
        
        
            | 
            | 
           35 | 
           	{
  | 
        
        
            | 
            | 
           36 | 
           		// check for the file
  | 
        
        
            | 
            | 
           37 | 
           		Net::WebRequest ^check = (Net::HttpWebRequest ^)Net::WebRequest::Create(url);
  | 
        
        
            | 
            | 
           38 | 
           		check->Credentials = Net::CredentialCache::DefaultCredentials;
  | 
        
        
            | 
            | 
           39 | 
           		Net::WebResponse ^response = (Net::HttpWebResponse ^)check->GetResponse();
  | 
        
        
            | 
            | 
           40 | 
           		// check the file size
  | 
        
        
            | 
            | 
           41 | 
           		__int64 fileSize = response->ContentLength;
  | 
        
        
            | 
            | 
           42 | 
           		if ( fileSize )
  | 
        
        
            | 
            | 
           43 | 
           			ret = CONNECTERROR_NONE;
  | 
        
        
            | 
            | 
           44 | 
              | 
        
        
            | 
            | 
           45 | 
           		response->Close();
  | 
        
        
            | 
            | 
           46 | 
              | 
        
        
            | 
            | 
           47 | 
           	}
  | 
        
        
            | 
            | 
           48 | 
           	catch (System::Net::WebException ^ex)
  | 
        
        
            | 
            | 
           49 | 
           	{
  | 
        
        
            | 
            | 
           50 | 
           		if ( ex->Status == System::Net::WebExceptionStatus::ConnectFailure )
  | 
        
        
            | 
            | 
           51 | 
           			ret = CONNECTERROR_FAILED;
  | 
        
        
            | 
            | 
           52 | 
           		else
  | 
        
        
            | 
            | 
           53 | 
           		{
  | 
        
        
            | 
            | 
           54 | 
           			switch ( cli::safe_cast<Net::HttpWebResponse ^>(ex->Response)->StatusCode )
  | 
        
        
            | 
            | 
           55 | 
           			{
  | 
        
        
            | 
            | 
           56 | 
           				case Net::HttpStatusCode::NotFound:
  | 
        
        
            | 
            | 
           57 | 
           					ret = CONNECTERROR_NOFILE;
  | 
        
        
            | 
            | 
           58 | 
           					break;
  | 
        
        
            | 
            | 
           59 | 
           				case Net::HttpStatusCode::RequestTimeout:
  | 
        
        
            | 
            | 
           60 | 
           					ret = CONNECTERROR_TIMEOUT;
  | 
        
        
            | 
            | 
           61 | 
           					break;
  | 
        
        
            | 
            | 
           62 | 
           				default:
  | 
        
        
            | 
            | 
           63 | 
           					ret = CONNECTERROR_UNKNOWN;
  | 
        
        
            | 
            | 
           64 | 
           			}
  | 
        
        
            | 
            | 
           65 | 
           		}
  | 
        
        
            | 
            | 
           66 | 
           	}
  | 
        
        
            | 
            | 
           67 | 
              | 
        
        
            | 
            | 
           68 | 
           	return ret;
  | 
        
        
            | 
            | 
           69 | 
           }
  | 
        
        
            | 
            | 
           70 | 
              | 
        
        
            | 
            | 
           71 | 
           inline String ^ReadDataFromWeb(String ^url)
  | 
        
        
            | 
            | 
           72 | 
           {
  | 
        
        
            | 
            | 
           73 | 
           	bool ret = false;
  | 
        
        
            | 
            | 
           74 | 
           	String ^data;
  | 
        
        
            | 
            | 
           75 | 
           	try 
  | 
        
        
            | 
            | 
           76 | 
           	{
  | 
        
        
            | 
            | 
           77 | 
           		System::Net::WebClient ^Client = gcnew System::Net::WebClient();
  | 
        
        
            | 
            | 
           78 | 
           		Client->Headers->Add( "user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)" );
  | 
        
        
            | 
            | 
           79 | 
           		System::IO::Stream ^strm = Client->OpenRead(url);
  | 
        
        
            | 
            | 
           80 | 
           		System::IO::StreamReader ^sr = gcnew System::IO::StreamReader(strm);
  | 
        
        
            | 
            | 
           81 | 
           		data = sr->ReadToEnd();
  | 
        
        
            | 
            | 
           82 | 
              | 
        
        
            | 
            | 
           83 | 
           		strm->Close();
  | 
        
        
            | 
            | 
           84 | 
           		sr->Close();
  | 
        
        
            | 
            | 
           85 | 
           	}
  | 
        
        
            | 
            | 
           86 | 
           	catch (System::Net::WebException ^)
  | 
        
        
            | 
            | 
           87 | 
           	{
  | 
        
        
            | 
            | 
           88 | 
           		return nullptr;
  | 
        
        
            | 
            | 
           89 | 
           	}
  | 
        
        
            | 
            | 
           90 | 
              | 
        
        
            | 
            | 
           91 | 
           	if ( data && data->Length )
  | 
        
        
            | 
            | 
           92 | 
           		return data;
  | 
        
        
            | 
            | 
           93 | 
           	return nullptr;
  | 
        
        
            | 
            | 
           94 | 
           }
  | 
        
        
            | 
            | 
           95 | 
              | 
        
        
            | 
            | 
           96 | 
           inline System::String ^SystemStringFromCyString ( CyString str )
  | 
        
        
            | 
            | 
           97 | 
           {
  | 
        
        
            | 
            | 
           98 | 
           	System::String ^Str = gcnew System::String(str.c_str());
  | 
        
        
            | 
            | 
           99 | 
           	return Str;
  | 
        
        
            | 
            | 
           100 | 
           }
  | 
        
        
           | 39 | 
           cycrow | 
           101 | 
           inline System::String ^_US(const Utils::String &str)
  | 
        
        
            | 
            | 
           102 | 
           {
  | 
        
        
            | 
            | 
           103 | 
           	System::String ^Str = gcnew System::String(str.c_str());
  | 
        
        
            | 
            | 
           104 | 
           	return Str;
  | 
        
        
            | 
            | 
           105 | 
           }
  | 
        
        
           | 1 | 
           cycrow | 
           106 | 
              | 
        
        
            | 
            | 
           107 | 
           inline System::Drawing::Bitmap ^LoadIcon(CBaseFile *p)
  | 
        
        
            | 
            | 
           108 | 
           {
  | 
        
        
            | 
            | 
           109 | 
           	CyString file = p->GetIcon()->GetFilePointer();
  | 
        
        
            | 
            | 
           110 | 
           	if ( !file.Empty() )
  | 
        
        
            | 
            | 
           111 | 
           	{
  | 
        
        
            | 
            | 
           112 | 
           		file = file.FindReplace("/", "\\").FindReplace("\\\\", "\\");
  | 
        
        
            | 
            | 
           113 | 
           		bool doIcon = false;
  | 
        
        
            | 
            | 
           114 | 
           		System::String ^sFile = SystemStringFromCyString(file);
  | 
        
        
            | 
            | 
           115 | 
           		if ( System::IO::File::Exists(sFile) )
  | 
        
        
            | 
            | 
           116 | 
           		{
  | 
        
        
            | 
            | 
           117 | 
           			Bitmap ^myBitmap = gcnew Bitmap(sFile);
  | 
        
        
            | 
            | 
           118 | 
           			return myBitmap;
  | 
        
        
            | 
            | 
           119 | 
           		}
  | 
        
        
            | 
            | 
           120 | 
           	}
  | 
        
        
            | 
            | 
           121 | 
              | 
        
        
            | 
            | 
           122 | 
           	return nullptr;
  | 
        
        
            | 
            | 
           123 | 
           }
  | 
        
        
            | 
            | 
           124 | 
              | 
        
        
            | 
            | 
           125 | 
           inline System::String ^GetProgramVersionString(float version, int beta)
  | 
        
        
            | 
            | 
           126 | 
           {
  | 
        
        
            | 
            | 
           127 | 
           	System::String ^str = "V" + SystemStringFromCyString(CyString::CreateFromFloat(version, 2));
  | 
        
        
            | 
            | 
           128 | 
           	// beta version
  | 
        
        
            | 
            | 
           129 | 
           	if ( beta > 0 )
  | 
        
        
            | 
            | 
           130 | 
           		str += " (Beta " + beta + ")";
  | 
        
        
            | 
            | 
           131 | 
           	// RC release
  | 
        
        
            | 
            | 
           132 | 
           	else if ( beta < 0 )
  | 
        
        
            | 
            | 
           133 | 
           		str += " (RC " + (0 - beta) + ")";
  | 
        
        
            | 
            | 
           134 | 
           	return str;
  | 
        
        
            | 
            | 
           135 | 
           }
  | 
        
        
            | 
            | 
           136 | 
              |