示例#1
0
void SaveStringList(const char *section, ccollect< carray<char> > &list)
{
	try {
		SysTextFileOut out;
				
		FSPath path = configDirPath;
		path.Push(CS_UTF8, carray_cat<char>(section, ".cfg").ptr());
		out.Open( (sys_char_t*)path.GetString(sys_charset_id) );
		
		for (int i = 0; i<list.count(); i++)
		{
			if (list[i].ptr() && list[i][0])
			{
				out.Put(list[i].ptr());
				out.PutC('\n');
			}
		}
		
		out.Flush();
		out.Close();
		
	} catch (cexception *ex) {
		ex->destroy();
		return ;
	}
}
示例#2
0
int LoadToTempFile( NCDialogParent* parent, clPtr<FS>* fs, FSPath* path )
{
	clPtr<FS> TempFs;
	FSPath TempPath;
	const int TempId = CreateWcmTempDir( &TempFs, &TempPath );
	if ( !TempId )
	{
		return 0;
	}

	// append file name to the created temp dir
	FSPath DstPath = TempPath;
	DstPath.Push( CS_UTF8, path->GetItem( path->Count() - 1 )->GetUtf8() );

	LoadFileDataThreadDlg dlg( parent, *fs, *path, TempFs, DstPath );
	dlg.RunNewThread( "Load file", LoadFileDataThreadFunc, &dlg.m_Data );
	dlg.DoModal();
	
	if ( !dlg.m_Data.m_Success )
	{
		// cleanup created temp dir
		RemoveWcmTempDir( TempId );
		return 0;
	}
	
	*fs = TempFs;
	*path = DstPath;
	return TempId;
}
示例#3
0
void WcmConfig::Save( NCWin* nc )
{
	if ( nc )
	{
		leftPanelPath = new_char_str( nc->GetLeftPanel()->GetPath().GetUtf8() );
		rightPanelPath = new_char_str( nc->GetRightPanel()->GetPath().GetUtf8() );
		crect Rect = nc->ScreenRect();
		windowX = Rect.top;
		windowY = Rect.left;
		windowWidth = Rect.Width();
		windowHeight = Rect.Height();
	}
	
#ifdef _WIN32
	for (int i = 0; i<mapList.count(); i++)
	{
		Node &node = mapList[i];
		if (node.type == MT_BOOL && node.ptr.pBool != 0)
			RegWriteInt(node.section, node.name, *node.ptr.pBool);
		else
		if (node.type == MT_INT && node.ptr.pInt != 0)
			RegWriteInt(node.section, node.name, *node.ptr.pInt);
		else
		if (node.type == MT_STR && node.ptr.pStr != 0)
			RegWriteString(node.section, node.name, node.ptr.pStr->ptr());
	}
#else 
	IniHash hash;
	FSPath path = configDirPath;
	path.Push(CS_UTF8, "config");
	hash.Load((sys_char_t*)path.GetString(sys_charset_id));

	for (int i = 0; i<mapList.count(); i++)
	{
		Node &node = mapList[i];
		if (node.type == MT_BOOL && node.ptr.pBool != 0)
			hash.SetBoolValue(node.section, node.name, *node.ptr.pBool);
		else
		if (node.type == MT_INT && node.ptr.pInt != 0)
			hash.SetIntValue(node.section, node.name, *node.ptr.pInt);
		else
		if (node.type == MT_STR && node.ptr.pStr != 0)
			hash.SetStrValue(node.section, node.name, node.ptr.pStr->ptr());
	}
	
	hash.Save((sys_char_t*)path.GetString(sys_charset_id));
#endif
}
示例#4
0
void WcmConfig::Load()
{
#ifdef _WIN32
	
	for (int i = 0; i<mapList.count(); i++)
	{
		Node &node = mapList[i];
		if (node.type == MT_BOOL && node.ptr.pBool != 0)
			*node.ptr.pBool = RegReadInt(node.section, node.name, node.def.defBool)!=0;
		else
		if (node.type == MT_INT && node.ptr.pInt != 0)
			*node.ptr.pInt = RegReadInt(node.section, node.name, node.def.defInt);
		else
		if (node.type == MT_STR && node.ptr.pStr != 0)
			*node.ptr.pStr = RegReadString(node.section, node.name, node.def.defStr);
	}

#else 
	IniHash hash;
	FSPath path = configDirPath;
	path.Push(CS_UTF8, "config");
	
	hash.Load(DEFAULT_CONFIG_PATH);
	hash.Load((sys_char_t*)path.GetString(sys_charset_id));

	for (int i = 0; i<mapList.count(); i++)
	{
		Node &node = mapList[i];
		if (node.type == MT_BOOL && node.ptr.pBool != 0)
			*node.ptr.pBool = hash.GetBoolValue(node.section, node.name, node.def.defBool);
		else
		if (node.type == MT_INT && node.ptr.pInt != 0)
			*node.ptr.pInt = hash.GetIntValue(node.section, node.name, node.def.defInt);
		else
		if (node.type == MT_STR && node.ptr.pStr != 0)
		{
			const char *s = hash.GetStrValue(node.section, node.name, node.def.defStr);
			if (s) *node.ptr.pStr = new_char_str(s);
			else (*node.ptr.pStr) = 0;
		}

	}
#endif
	if (editTabSize<=0 || editTabSize >64) editTabSize = 8;
}
示例#5
0
clPtr<FS> Plugin_OpenFS( clPtr<FS> Fs, FSPath Path, const char* Name )
{
	// get path with filename
	Path.Push( CS_UTF8, Name );

	for ( auto& iter : clPluginFactory::s_Registry )
	{
		const clPluginFactory* PluginFactory = iter.second;

		clPtr<FS> Vfs = PluginFactory->OpenFS( Fs, Path );

		if ( Vfs.Ptr() != nullptr )
		{
			return Vfs;
		}
	}

	return clPtr<FS>();
}
示例#6
0
bool LoadStringList(const char *section, ccollect< carray<char> > &list)
{
	try {
		SysTextFileIn in;
				
		FSPath path = configDirPath;
		path.Push(CS_UTF8, carray_cat<char>(section, ".cfg").ptr());
		in.Open( (sys_char_t*)path.GetString(sys_charset_id) );
		
		char buf[4096];
		while (in.GetLine(buf, sizeof(buf))) 
		{
			char *s = buf;
			while (*s>0 && *s<=' ') s++;
			if (*s) list.append(new_char_str(s));
		}
	} catch (cexception *ex) {
		ex->destroy();
		return false;
	}
	return true;
}
int FSSftp::ReadDir  ( FSList* list, FSPath& path, int* err, FSCInfo* info )
{
	MutexLock lock( &mutex );
	int ret = CheckSession( err, info );

	if ( ret ) { return ret; }

	if ( !list ) { return 0; }

	list->Clear();

	try
	{

		LIBSSH2_SFTP_HANDLE* dir = 0;

		try
		{

			while ( true )
			{
				dir = libssh2_sftp_opendir( sftpSession, ( char* )path.GetString( _operParam.charset, '/' ) );

				if ( dir ) { break; }

				CheckSFTPEagain();
				WaitSocket( info );
			}

			while ( true )
			{
				char buf[4096];
				int len = 0;
				SftpAttr attr;


				WHILE_EAGAIN_( len, libssh2_sftp_readdir( dir, buf, sizeof( buf ) - 1, &attr.attr ) );

				if ( len < 0 ) { CheckSFTP( len ); }

				if ( len == 0 ) { break; }

				if ( buf[0] == '.' && ( !buf[1] || ( buf[1] == '.' && !buf[2] ) ) )
				{
					continue;
				}

				clPtr<FSNode> pNode = new FSNode();
				pNode->name.Set( _operParam.charset, buf );

				if ( attr.IsLink() )
				{
					FSPath pt = path;
					pt.Push( _operParam.charset, buf );
					char* fullPath = ( char* )pt.GetString( _operParam.charset, '/' );

					WHILE_EAGAIN_( len, libssh2_sftp_readlink( sftpSession, fullPath, buf, sizeof( buf ) - 1 ) );

					if ( len < 0 ) { CheckSFTP( len ); }

					pNode->st.link.Set( _operParam.charset, buf );

					int ret;
					WHILE_EAGAIN_( ret, libssh2_sftp_stat( sftpSession, fullPath, &attr.attr ) );
				}

				pNode->st.mode = attr.Permissions();
				pNode->st.size = attr.Size();
				pNode->st.uid = attr.Uid();
				pNode->st.gid = attr.Gid();
				pNode->st.mtime = attr.MTime();

				list->Append( pNode );
			}

		}
		catch ( ... )
		{
			if ( dir ) { CloseHandle( dir, info ); }

			throw;
		}

		if ( dir ) { CloseHandle( dir, info ); }

	}
	catch ( int e )
	{
		if ( err ) { *err = e; }

		return ( e == -2 ) ? -2 : -1;
	}

	return 0;
}
int FSSftp::ReadDir  ( FSList* list, FSPath& path, int* err, FSCInfo* info )
{
	MutexLock lock( &mutex );
	int ret = CheckSession( err, info );

	if ( ret ) { return ret; }

	if ( !list ) { return 0; }

	list->Clear();

	sftp_dir dir = sftp_opendir( sftpSession, ( char* )path.GetString( _operParam.charset ) );

	if ( !dir )
	{
		if ( err ) { *err = sftp_get_error( sftpSession ); }

		return -1;
	}

	try
	{

		while ( true )
		{
			if ( info && info->Stopped() )
			{
				sftp_closedir( dir );
				return -2;
			}

			sftp_attributes attr = sftp_readdir( sftpSession, dir );

			if ( !attr )
			{
				if ( sftp_dir_eof( dir ) ) { break; }

				if ( err ) { *err = sftp_get_error( sftpSession ); }

				return -1;
			}

			try
			{
				//skip . and ..
				if ( !attr->name || attr->name[0] == '.' && ( !attr->name[1] || ( attr->name[1] == '.' && !attr->name[2] ) ) )
				{
					continue;
				}

				clPtr<FSNode> pNode = new FSNode();
				pNode->name.Set( _operParam.charset, attr->name );

				pNode->st.size = attr->size;
				pNode->st.uid = attr->uid;
				pNode->st.gid = attr->gid;
				pNode->st.mtime = attr->mtime;

				if ( attr->type == SSH_FILEXFER_TYPE_SYMLINK )
				{
					FSPath pt = path;
					pt.Push( _operParam.charset, attr->name );
					char* fullPath = ( char* )pt.GetString( _operParam.charset );
					char* s = sftp_readlink( sftpSession, fullPath );

					if ( s ) { pNode->st.link.Set( _operParam.charset, s ); }

					sftp_attributes a = sftp_stat( sftpSession, fullPath );

					if ( a )
					{
						pNode->st.mode  = a->permissions;
						pNode->st.mtime = a->mtime;
						sftp_attributes_free( a );
					}
					else
					{
						pNode->st.mode = 0;
					}
				}
				else
				{
					pNode->st.mode = attr->permissions;
				}

				list->Append( pNode );

				sftp_attributes_free( attr );

			}
			catch ( ... )
			{
				sftp_attributes_free( attr );
				throw;
			}
		};

		sftp_closedir( dir );
	}
	catch ( ... )
	{
		sftp_closedir( dir );
		throw;
	}

	return 0;
}