示例#1
0
BOOL CDlgFileConv::OnInitDialog() 
{
	CDialog::OnInitDialog();

	CWnd::DragAcceptFiles();

	//所有支持的编码
	char *p, *charsets;
	charsets = strdupa(supported_charsets);
	while (p = strsep(&charsets, " "))
	{
		((CComboBox*)GetDlgItem(IDC_CB_SRC_CHARSET))->AddString(stringToCString(p));
		((CComboBox*)GetDlgItem(IDC_CB_DST_CHARSET))->AddString(stringToCString(p));
	}

	//默认选择文件
	m_rdSrcFile.SetCheck(TRUE);
	SwitchSrcType();

	m_bRecurDir = TRUE;
	m_bWriteBOM = TRUE;
	m_bConverting = FALSE;

	m_progTotal.SetRange(0, 100);

	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
示例#2
0
static void systemGetEnv(Thread *thread) {
    char *env = getenv(stringToCString(thread->variable(0).object));

    if (!env) {
        thread->returnNothingnessFromFunction();
        return;
    }

    thread->returnOEValueFromFunction(stringFromChar(env));
}
示例#3
0
文件: VyNetwork.c 项目: mueschm/Vyper
//Read in a message from a UDP connection
VyMessage* readUDPMessage(VyConn* conn)
{
	//String to hold the incoming data
	VyString* message = NULL;
	//Buffer to hold the data being read as it comes in
	unsigned char* buffer = malloc(sizeof(char)*1024);
	//The amount of data read in
	int readSize;
	
	//Information about the data being read in
	int addr_len;
    struct sockaddr_in client_addr;
	
	//Keep reading data until there is no more to read
	while((readSize = recvfrom(conn->socket,buffer,1024,0,(struct sockaddr *)&client_addr, &addr_len)) >= 1)
		//Add the data to the message
		message = addCharToStringSafe(message,buffer,readSize);
	
	free(buffer);
	
	//Make sure we recieved a message
	if(message == NULL)
		return NULL;
	
	//Get the ip for the person who sent the message
	char* ip = inet_ntoa(client_addr.sin_addr);
	if(ip != NULL)
	    conn->ip = copyCString(ip);
	else
	    conn->ip = NULL;

	//Convert the VyString to a char array
	unsigned char* cStringMessage = stringToCString(message);

	//Convert the char array to a VyMessage
	VyMessage* returnMessage = parseNewMessage(cStringMessage);

	free(cStringMessage);
	destroyVyString(message);
	
	//Print out information for debug and display
	printf(" - UUID: <%s> ",returnMessage->senderID);
	printf(": Received UDP message: [%s]",returnMessage->command);
	printf(" <%i> ",returnMessage->messageSize);
	printf(" [%s]\n",returnMessage->data);

	return returnMessage;
}
示例#4
0
文件: VyNetwork.c 项目: mueschm/Vyper
//Read in a message from a ssl connection
VyMessage* readSSLMessage(VySSL* ssl)
{
	//String to hold the incoming data
	VyString* message = NULL;
	//Buffer to hold the data being read as it comes in
	unsigned char* buffer = malloc(sizeof(char)*1024);
	//The amount of data read in
	int readSize;

	//Loop while data is coming in
	while((readSize = SSL_read(ssl->ssl, buffer, sizeof(buffer))) >= 1)
		//Add the data to the current string
		message = addCharToStringSafe(message,buffer,readSize);
	
	//Clear up the buffer
	free(buffer);
	
	//Make sure we have recieved the message
	if(message == NULL)
		return NULL;

	//Convert the VyString to a char array
	unsigned char* cStringMessage = stringToCString(message);

	//Convert the char array to a VyMessage
	VyMessage* returnMessage = parseNewMessage(cStringMessage);

	//Clean up data
	free(cStringMessage);
	destroyVyString(message);
	
	//Print out data for debug and display
	printf(" - UUID: <%s> ",returnMessage->senderID);
	printf(": Received SSL message: [%s]",returnMessage->command);
	printf(" <%i> ",returnMessage->messageSize);
	printf(" [%s]\n",returnMessage->data);

	return returnMessage;
}
示例#5
0
文件: VyNetwork.c 项目: mueschm/Vyper
//Read in a message from a TCP connection
VyMessage* readMessage(VyConn* conn)
{
	//String to hold the incoming data
	VyString* message = NULL;
	//Buffer to hold the data being read as it comes in
	unsigned char* buffer = malloc(sizeof(char)*1024);
	//The amount of data read in
	int readSize;

	//Keep looping while data is being read in
	while((readSize = read(conn->socket, buffer, 1023)) >= 1)
		//Add the new data to the message
		message = addCharToStringSafe(message,buffer,readSize);
	
	free(buffer);
	
	//Make sure we recieved data
	if(message == NULL)
		return NULL;

	//Convert the VyString to a char array
	unsigned char* cStringMessage = stringToCString(message);

	//Convert the char array to a VyMessage
	VyMessage* returnMessage = parseNewMessage(cStringMessage);

	//Free up data
	free(cStringMessage);
	destroyVyString(message);
	
	//Show message information for debug and display
	printf(" - Unique ID: %s - ",returnMessage->senderID);
	printf(" - Received TCP message: [%s]",returnMessage->command);
	printf(" <%i> ",returnMessage->messageSize);
	printf(" - [%s]\n",returnMessage->data);

	return returnMessage;
}
示例#6
0
static void systemSystem(Thread *thread) {
    FILE *f = popen(stringToCString(thread->variable(0).object), "r");

    if (f == nullptr) {
        thread->returnNothingnessFromFunction();
        return;
    }

    size_t bufferUsedSize = 0;
    int bufferSize = 50;
    auto buffer = thread->retain(newArray(bufferSize));

    while (fgets(buffer->val<char>() + bufferUsedSize, bufferSize - (int)bufferUsedSize, f) != nullptr) {
        bufferUsedSize = strlen(buffer->val<char>());

        if (bufferSize - bufferUsedSize < 2) {
            bufferSize *= 2;
            buffer = resizeArray(buffer.unretainedPointer(), bufferSize, thread);
        }
    }

    bufferUsedSize = strlen(buffer->val<char>());

    EmojicodeInteger len = u8_strlen_l(buffer->val<char>(), bufferUsedSize);

    auto so = thread->retain(newObject(CL_STRING));
    auto *string = so->val<String>();
    string->length = len;

    Object *chars = newArray(len * sizeof(EmojicodeChar));
    string = so->val<String>();
    string->charactersObject = chars;

    u8_toucs(string->characters(), len, buffer->val<char>(), bufferUsedSize);
    thread->release(2);
    thread->returnFromFunction(so.unretainedPointer());
}
示例#7
0
void CDlgFileConv::OnOK()
{
	UpdateData(TRUE);

	//中止转换
	if (m_bConverting)
	{
		m_bTerminate = TRUE;
		return;
	}

	ConvFileInfo& cfi = m_convFileInfo;
	cfi.src_files.clear();
	cfi.dst_files.clear();
	cfi.src_charset = "";
	cfi.dst_charset = "";
	cfi.total = cfi.success = cfi.failed = 0;

	//转换源信息
	std::string src;
	if (m_rdSrcFile.GetCheck())
	{
		src = CStringToUTF8string(m_strSrcFile);
		if (src.empty())
		{
			AfxMessageBox(_T("请选择一个待转换的文件!"));
			return;
		}

		cfi.src_files.push_back(src);
	}
	else
	{
		src = CStringToUTF8string(m_strSrcDir);
		if (src.empty())
		{
			AfxMessageBox(_T("请选择一个待转换的目录!"));
			return;
		}
		
		if (src.length() == 3)
		{
			AfxMessageBox(_T("无法转换整个驱动器!"));
			return;
		}

		foreach_file(src.c_str(), handle_src_file, m_bRecurDir, 1, &cfi.src_files);

		if (cfi.src_files.size() == 0)
		{
			AfxMessageBox(_T("选择的目录下没有需要转换的文件!"));
			return;
		}
	}

	if (m_strSrcCharset.IsEmpty())
	{
		AfxMessageBox(_T("请选择源文件编码格式!"));
		return;
	}
	cfi.src_charset = CStringToUTF8string(m_strSrcCharset);

	//目标信息
	std::string save_dir;
	if (m_bSaveSameDir)
		save_dir = utils::PathFindDirectory(src);
	else
	{
		save_dir = CStringToUTF8string(m_strDstDir);
		if (save_dir.empty())
		{
			AfxMessageBox(_T("请选择保存目录!"));
			return;
		}
	}
	utils::EndWith(save_dir, PATH_SEP_CHAR);

	if (m_strDstCharset.IsEmpty())
	{
		AfxMessageBox(_T("请选择目标文件编码格式!"));
		return;
	}
	cfi.dst_charset = CStringToUTF8string(m_strDstCharset);

	//生成保存文件路径
	if (m_rdSrcFile.GetCheck())
	{
		std::string dstf;
		if (save_dir == utils::PathFindDirectory(src))
		{
			dstf = src.insert(src.length() - utils::PathFindExtension(src).length(), \
								CStringToUTF8string(m_strDstCharset).insert(0, "_"));
		}
		else
			dstf = save_dir + utils::PathFindFileName(src);

		if (utils::PathFileExists(dstf))
		{
			std::string msg = "文件 ";
			msg += utils::UTF8stringTostring(dstf);
			msg += "已经存在,是否覆盖?";
			
			if (AfxMessageBox(stringToCString(msg), MB_OKCANCEL) != IDOK)
				return;
		}

		cfi.dst_files.push_back(dstf);
	}
	else
	{
		utils::string_list::iterator it;
		std::string srcf, dstf;

		if (save_dir == utils::PathFindDirectory(src))
		{
			save_dir += utils::PathFindFileName(src);
			save_dir += "_";
			save_dir += CStringToUTF8string(m_strDstCharset);
		}
		else
			save_dir += utils::PathFindFileName(src);

		if (utils::PathFileExists(save_dir))
		{
			std::string msg = "目录 ";
			msg += utils::UTF8stringTostring(save_dir);
			msg += "已经存在,是否覆盖?";

			if (AfxMessageBox(stringToCString(msg), MB_OKCANCEL) != IDOK)
				return;
		}

		for (it = cfi.src_files.begin(); it != cfi.src_files.end(); it++)
		{
			srcf = *it;
			dstf = srcf.replace(0, src.length(), save_dir);
			cfi.dst_files.push_back(dstf);
		}
	}

	//开启转换线程
	m_bConverting = TRUE;
	uthread_create(&m_thread, conv_thread_proc, this, 0);

	m_bTerminate = FALSE;
	SetDlgItemText(IDOK, _T("停止转换"));
}
示例#8
0
wstring CStringConverter::stringTowstring( string const &strSource )
{
	return CStringTowstring(stringToCString(strSource));
}
示例#9
0
CString CStringConverter::stringstreamToCString( stringstream const &ss )
{
	string strTemp = ss.str();
	return stringToCString(strTemp);
}