Example #1
1
void CLocalListView::DisplayShares(wxString computer)
{
	// Cast through a union to avoid warning about breaking strict aliasing rule
	union
	{
		SHARE_INFO_1* pShareInfo;
		LPBYTE pShareInfoBlob;
	} si;

	DWORD read, total;
	DWORD resume_handle = 0;

	if (computer.Last() == '\\')
		computer.RemoveLast();

	int j = m_fileData.size();
	int share_count = 0;
	int res = 0;
	do
	{
		const wxWX2WCbuf buf = computer.wc_str(wxConvLocal);
		res = NetShareEnum((wchar_t*)(const wchar_t*)buf, 1, &si.pShareInfoBlob, MAX_PREFERRED_LENGTH, &read, &total, &resume_handle);

		if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
			break;

		SHARE_INFO_1* p = si.pShareInfo;
		for (unsigned int i = 0; i < read; i++, p++)
		{
			if (p->shi1_type != STYPE_DISKTREE)
				continue;

			CLocalFileData data;
			data.flags = normal;
			data.name = p->shi1_netname;
#ifdef __WXMSW__
			data.label = data.name;
#endif
			data.dir = true;
			data.icon = -2;
			data.size = -1;

			m_fileData.push_back(data);
			m_indexMapping.push_back(j++);

			share_count++;
		}

		NetApiBufferFree(si.pShareInfo);
	}
	while (res == ERROR_MORE_DATA);

	if (m_pFilelistStatusBar)
		m_pFilelistStatusBar->SetDirectoryContents(0, share_count, 0, false, 0);
}
Example #2
0
wxString CFormat::GetIntegerField(const wxChar* fieldType)
{
	const wxString field = GetCurrentField();
	if (field.IsEmpty()) {
		// Invalid or missing field ...
		return field;
	}

	// Drop type and length
	wxString newField = field;
	while (isalpha(newField.Last())) {
		newField.RemoveLast();
	}
	
	// Set the correct integer type
	newField += fieldType;

	switch ((wxChar)field.Last()) {
		case wxT('o'):		// Unsigned octal
		case wxT('x'):		// Unsigned hexadecimal integer
		case wxT('X'):		// Unsigned hexadecimal integer (capital letters)
			// Override the default type
			newField.Last() = field.Last();
		
		case wxT('d'):		// Signed decimal integer
		case wxT('i'):		// Signed decimal integer
		case wxT('u'):		// Unsigned decimal integer
			return newField;
		
		default:
			wxFAIL_MSG(wxT("Integer value passed to non-integer format string: ") + m_format);
			SetCurrentField(field);
			return wxEmptyString;
	}
}
Example #3
0
bool CState::RecursiveCopy(wxString source, wxString target)
{
	if (source == _T(""))
		return false;

	if (target == _T(""))
		return false;

	if (target.Last() != wxFileName::GetPathSeparator())
		target += wxFileName::GetPathSeparator();

	if (source.Last() == wxFileName::GetPathSeparator())
		source.RemoveLast();

	if (source + wxFileName::GetPathSeparator() == target)
		return false;

	if (target.Len() > source.Len() && source == target.Left(source.Len()) && target[source.Len()] == wxFileName::GetPathSeparator())
		return false;
	
	int pos = source.Find(wxFileName::GetPathSeparator(), true);
	if (pos == -1 || pos == (int)source.Len() - 1)
		return false;

	std::list<wxString> dirsToVisit;
	dirsToVisit.push_back(source.Mid(pos + 1) + wxFileName::GetPathSeparator());
	source = source.Left(pos + 1);

	// Process any subdirs which still have to be visited
	while (!dirsToVisit.empty())
	{
		wxString dirname = dirsToVisit.front();
		dirsToVisit.pop_front();
		wxMkdir(target + dirname);
		wxDir dir;
		if (!dir.Open(source + dirname))
			continue;

		wxString file;
		for (bool found = dir.GetFirst(&file); found; found = dir.GetNext(&file))
		{
			if (file == _T(""))
			{
				wxGetApp().DisplayEncodingWarning();
				continue;
			}
			if (wxFileName::DirExists(source + dirname + file))
			{
				const wxString subDir = dirname + file + wxFileName::GetPathSeparator();
				dirsToVisit.push_back(subDir);
			}
			else
				wxCopyFile(source + dirname + file, target + dirname + file);
		}
	}

	return true;
}
Example #4
0
wxString wxSTEditorOptions::FixConfigPath(const wxString& path, bool add_sep)
{
    if (add_sep && (!path.Length() || (path.Last() != wxT('/'))))
        return path + wxT("/");
    if (!add_sep && path.Length() && (path.Last() == wxT('/')))
        return path.Mid(0, path.Length()-1);

    return path;
}
bool cbResolveSymLinkedDirPath(wxString& dirpath)
{
#ifdef _WIN32
    return false;
#else
    if (dirpath.Last() == wxFILE_SEP_PATH)
        dirpath.RemoveLast();

    struct stat fileStats;
    if (lstat(dirpath.mb_str(wxConvUTF8), &fileStats) != 0)
        return false;

    // If the path is a symbolic link, then try to resolve it.
    // This is needed to prevent infinite loops, when a folder is pointing to itself or its parent folder.
    if (S_ISLNK(fileStats.st_mode))
    {
        char buffer[4096];
        int result = readlink(dirpath.mb_str(wxConvUTF8), buffer, WXSIZEOF(buffer) - 1);
        if (result != -1)
        {
            buffer[result] = '\0'; // readlink() doesn't NUL-terminate the buffer
            wxString pathStr(buffer, wxConvUTF8);
            wxFileName fileName = wxFileName::DirName(pathStr);

            // If this is a relative symbolic link, we need to make it absolute.
            if (!fileName.IsAbsolute())
            {
                wxFileName dirNamePath;
                if (dirpath.Last() == wxFILE_SEP_PATH)
                    dirNamePath = wxFileName::DirName(dirpath);
                else
                    dirNamePath = wxFileName::DirName(dirpath + wxFILE_SEP_PATH);
                dirNamePath.RemoveLastDir();
                // Make the new filename absolute relative to the parent folder.
                fileName.MakeAbsolute(dirNamePath.GetFullPath());
            }

            wxString fullPath = fileName.GetFullPath();
            if (fullPath.Last() == wxT('.')) // this case should be handled because of a bug in wxWidgets
                fullPath.RemoveLast();
            if (fullPath.Last() == wxFILE_SEP_PATH)
                fullPath.RemoveLast();
            dirpath = fullPath;
            return true;
        }
    }

    return false;
#endif // _WIN32
}
Example #6
0
bool CLocalFileSystem::BeginFindFiles(wxString path, bool dirs_only)
{
	EndFindFiles();

	m_dirs_only = dirs_only;
#ifdef __WXMSW__
	if (path.Last() != '/' && path.Last() != '\\') {
		m_find_path = path + _T("\\");
		path += _T("\\*");
	}
	else {
		m_find_path = path;
		path += '*';
	}

	m_hFind = FindFirstFileEx(path, FindExInfoStandard, &m_find_data, dirs_only ? FindExSearchLimitToDirectories : FindExSearchNameMatch, 0, 0);
	if (m_hFind == INVALID_HANDLE_VALUE) {
		m_found = false;
		return false;
	}

	m_found = true;
	return true;
#else
	if (path != _T("/") && path.Last() == '/')
		path.RemoveLast();

	const wxCharBuffer s = path.fn_str();

	m_dir = opendir(s);
	if (!m_dir)
		return false;

	const wxCharBuffer p = path.fn_str();
	const int len = strlen(p);
	m_raw_path = new char[len + 2048 + 2];
	m_buffer_length = len + 2048 + 2;
	strcpy(m_raw_path, p);
	if (len > 1)
	{
		m_raw_path[len] = '/';
		m_file_part = m_raw_path + len + 1;
	}
	else
		m_file_part = m_raw_path + len;

	return true;
#endif
}
Example #7
0
enum CLocalFileSystem::local_fileType CLocalFileSystem::GetFileType(const wxString& path)
{
#ifdef __WXMSW__
	DWORD result = GetFileAttributes(path);
	if (result == INVALID_FILE_ATTRIBUTES)
		return unknown;

	if (result & FILE_ATTRIBUTE_DIRECTORY)
		return dir;

	return file;
#else
	if (path.Last() == wxFileName::GetPathSeparator() && path != wxFileName::GetPathSeparator())
	{
		wxString tmp = path;
		tmp.RemoveLast();
		return GetFileType(tmp);
	}

	wxStructStat buf;
	int result = wxLstat(path, &buf);
	if (result)
		return unknown;

#ifdef S_ISLNK
	if (S_ISLNK(buf.st_mode))
		return link;
#endif

	if (S_ISDIR(buf.st_mode))
		return dir;

	return file;
#endif
}
Example #8
0
/* ------------------------------------------------------------------------------
 function ChompPathDelim(const Path: string): string;
 ------------------------------------------------------------------------------ */
wxString ChompPathDelim(wxString const & Path)
{
	if ((Path.Length() != 0) && (Path.Last() == PathDelim))
		return LeftStr(Path, Length(Path) - 1);
	else
		return Path;
}
Example #9
0
wxString wxFileDialogBase::AppendExtension(const wxString &filePath,
                                           const wxString &extensionList)
{
    // strip off path, to avoid problems with "path.bar/foo"
    wxString fileName = filePath.AfterLast(wxFILE_SEP_PATH);

    // if fileName is of form "foo.bar" it's ok, return it
    int idx_dot = fileName.Find(wxT('.'), true);
    if ((idx_dot != wxNOT_FOUND) && (idx_dot < (int)fileName.length() - 1))
        return filePath;

    // get the first extension from extensionList, or all of it
    wxString ext = extensionList.BeforeFirst(wxT(';'));

    // if ext == "foo" or "foo." there's no extension
    int idx_ext_dot = ext.Find(wxT('.'), true);
    if ((idx_ext_dot == wxNOT_FOUND) || (idx_ext_dot == (int)ext.length() - 1))
        return filePath;
    else
        ext = ext.AfterLast(wxT('.'));

    // if ext == "*" or "bar*" or "b?r" or " " then its not valid
    if ((ext.Find(wxT('*')) != wxNOT_FOUND) ||
        (ext.Find(wxT('?')) != wxNOT_FOUND) ||
        (ext.Strip(wxString::both).empty()))
        return filePath;

    // if fileName doesn't have a '.' then add one
    if (filePath.Last() != wxT('.'))
        ext = wxT(".") + ext;

    return filePath + ext;
}
Example #10
0
void SjLogGui::ExplodeMessage(const wxString& all___, unsigned long& severity, unsigned long& time, wxString& msg, wxString& scope)
{
	wxString temp;

	// get and strip severity
	temp = all___.BeforeFirst(wxT('|'));
	temp.ToULong(&severity);
	msg = all___.AfterFirst(wxT('|'));

	// get and strip time
	temp = msg.BeforeFirst(wxT('|'));
	temp.ToULong(&time);
	msg = msg.AfterFirst(wxT('|'));

	// now "msg" is message and optional scope enclosured by "[]"
	scope.Empty();
	int p = msg.Find(wxT('['), true/*from end*/);
	if( p!=-1 )
	{
		scope = msg.Mid(p+1);
		if( scope.Len()>=1 && scope.Last()==wxT(']') )
		{
			scope = scope.Left(scope.Len()-1);
			msg = msg.Left(p).Trim();
		}
	}

	// some finalizing translations (some stuff is logged before the translation system is available)
	if( msg.StartsWith(wxT("Loading "), &temp) )
	{
		msg.Printf(_("Loading %s"), temp.c_str());
	}
}
Example #11
0
void MANFrame::GetMatches(const wxString &keyword, std::vector<wxString> *files_found)
{
    if (m_dirsVect.empty() || keyword.IsEmpty())
    {
        return;
    }

    for (std::vector<wxString>::iterator i = m_dirsVect.begin(); i != m_dirsVect.end(); ++i)
    {
        wxArrayString files;

        if (keyword.Last() == _T('*'))
        {
            wxDir::GetAllFiles(*i, &files, keyword);
        }
        else
        {
            wxDir::GetAllFiles(*i, &files, keyword + _T("*"));
        }

        for (size_t j = 0; j < files.GetCount(); ++j)
        {
            files_found->push_back(files[j]);
        }
    }
}
Example #12
0
wxRegKey::StdKey wxRegKey::ExtractKeyName(wxString& strKey)
{
  wxString strRoot = strKey.BeforeFirst(REG_SEPARATOR);

  size_t ui;
  for ( ui = 0; ui < nStdKeys; ui++ ) {
    if ( strRoot.CmpNoCase(aStdKeys[ui].szName) == 0 ||
         strRoot.CmpNoCase(aStdKeys[ui].szShortName) == 0 ) {
      break;
    }
  }

  if ( ui == nStdKeys ) {
    wxFAIL_MSG(wxT("invalid key prefix in wxRegKey::ExtractKeyName."));

    ui = HKCR;
  }
  else {
    strKey = strKey.After(REG_SEPARATOR);
    if ( !strKey.empty() && strKey.Last() == REG_SEPARATOR )
      strKey.Truncate(strKey.Len() - 1);
  }

  return (StdKey)ui;
}
Example #13
0
extern bool
wxGetDirectoryTimes(const wxString& dirname,
                    FILETIME *ftAccess, FILETIME *ftCreate, FILETIME *ftMod)
{
#ifdef __WXWINCE__
    // FindFirst() is going to fail
    wxASSERT_MSG( !dirname.empty(),
                  wxT("incorrect directory name format in wxGetDirectoryTimes") );
#else
    // FindFirst() is going to fail
    wxASSERT_MSG( !dirname.empty() && dirname.Last() != wxT('\\'),
                  wxT("incorrect directory name format in wxGetDirectoryTimes") );
#endif

    FIND_STRUCT fs;
    FIND_DATA fd = FindFirst(dirname, &fs);
    if ( !IsFindDataOk(fd) )
    {
        return false;
    }

    *ftAccess = fs.ftLastAccessTime;
    *ftCreate = fs.ftCreationTime;
    *ftMod = fs.ftLastWriteTime;

    FindClose(fd);

    return true;
}
Example #14
0
bool CLocalTreeView::CheckSubdirStatus(wxTreeItemId& item, const wxString& path)
{
	wxTreeItemIdValue value;
	wxTreeItemId child = GetFirstChild(item, value);

	static const wxLongLong size(-1);

#ifdef __WXMAC__
	// By default, OS X has a list of servers mounted into /net,
	// listing that directory is slow.
	if (GetItemParent(item) == GetRootItem() && (path == _T("/net") || path == _T("/net/")))
	{
			CFilterManager filter;

			const int attributes = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
			if (!filter.FilenameFiltered(_T("localhost"), path, true, size, true, attributes))
			{
				if (!child)
					AppendItem(item, _T(""));
				return true;
			}
	}
#endif

	if (child)
	{
		if (GetItemText(child) != _T(""))
			return false;

		CTreeItemData* pData = (CTreeItemData*)GetItemData(child);
		if (pData)
		{
			bool wasLink;
			int attributes;
			enum CLocalFileSystem::local_fileType type;
			if (path.Last() == CLocalFileSystem::path_separator)
				type = CLocalFileSystem::GetFileInfo(path + pData->m_known_subdir, wasLink, 0, 0, &attributes);
			else
				type = CLocalFileSystem::GetFileInfo(path + CLocalFileSystem::path_separator + pData->m_known_subdir, wasLink, 0, 0, &attributes);
			if (type == CLocalFileSystem::dir)
			{
				CFilterManager filter;
				if (!filter.FilenameFiltered(pData->m_known_subdir, path, true, size, true, attributes))
					return true;
			}
		}
	}

	wxString sub = HasSubdir(path);
	if (sub != _T(""))
	{
		wxTreeItemId subItem = AppendItem(item, _T(""));
		SetItemData(subItem, new CTreeItemData(sub));
	}
	else if (child)
		Delete(child);

	return true;
}
void ScriptConsole::Log(const wxString& msg)
{
    txtConsole->AppendText(msg);
    if (msg.Last() != _T('\n'))
        txtConsole->AppendText(_T('\n'));
//    txtConsole->ScrollLines(-1);
    Manager::ProcessPendingEvents();
}
Example #16
0
/* ------------------------------------------------------------------------------
 function AppendPathDelim(const Path: string): string;
 ------------------------------------------------------------------------------ */
wxString AppendPathDelim(wxString const & Path)
{
	wxString result;
	if ((Path.Length() != 0) && (Path.Last() != PathDelim))
		result = Path + PathDelim;
	else
		result = Path;
	return result;
}
Example #17
0
void ecRunTestsOutputDialog::AddLogMsg(const wxString& msg)
{
    wxString msg2(msg);

    if ((msg == wxEmptyString) || (msg.Last() != wxT('\n')))
        msg2 += wxT("\n");

    AddText(msg2);
}
void CRapiFileDialog::SetPathName(wxString strPath, bool bUpdateHistory)
{
    if(bUpdateHistory && (m_history.size()==0 || m_history.back()!=m_pathname.GetFullPath()))
    {
        m_history.push_back(m_pathname.GetFullPath());
        if(m_history.size()==256)
        {
            m_history.pop_front();
        }
    }
    
    if(strPath.IsEmpty())
    {
        strPath=wxT("\\");
    }

    wxFileName newfname;
    if(strPath.Last()==wxT('\\'))
    {
        newfname=wxFileName(strPath,wxT(""));
    }
    else
    {
        newfname=wxFileName(strPath);
    }

    GetOk()->Enable(strPath.Last()!=wxT('\\'));

    bool bUpdateView=false;
    if(m_pathname.GetPath(false,wxPATH_UNIX)!=newfname.GetPath(false,wxPATH_UNIX))
    {
        bUpdateView=true;
    }

    m_pathname=newfname;

    GetFileName()->SetValue(m_pathname.GetFullName());
    
    if(bUpdateView)
    {
        UpdateDialog();
    }
}
Example #19
0
/*
 * Compute the 'next' pad number for autoincrement
 * aPadName is the last pad name used
 * */
static wxString GetNextPadName( wxString aPadName )
{
    // Automatically increment the current pad number.
    int num    = 0;
    int ponder = 1;

    // Trim and extract the trailing numeric part
    while( aPadName.Len() && aPadName.Last() >= '0' && aPadName.Last() <= '9' )
    {
        num += ( aPadName.Last() - '0' ) * ponder;
        aPadName.RemoveLast();
        ponder *= 10;
    }

    num++;  // Use next number for the new pad
    aPadName << num;

    return aPadName;
}
static double ParseLatLon(wxString s)
{
    if(s.empty())
        return NAN;

    wxChar ns = s.Last();
    int sign = (ns == 'S' || ns == 'W') ? -1 : 1;
    double d;
    s.ToDouble(&d);
    return sign * d;
}
jewel::Decimal
wx_to_decimal
(   wxString wxs,
    wxLocale const& loc,
    DecimalParsingFlags p_flags
)
{
    bool const allow_parens =
        p_flags.test(string_flags::allow_negative_parens);
    wxs = wxs.Trim().Trim(false);  // trim both right and left.
    typedef wxChar CharT;
    static CharT const open_paren = wxChar('(');
    static CharT const close_paren = wxChar(')');
    static CharT const minus_sign = wxChar('-');
    wxString const decimal_point_s = loc.GetInfo
    (   wxLOCALE_DECIMAL_POINT,
        wxLOCALE_CAT_MONEY
    );
    wxString const thousands_sep_s = loc.GetInfo
    (   wxLOCALE_THOUSANDS_SEP,
        wxLOCALE_CAT_MONEY
    );
    if (wxs.IsEmpty())
    {
        return Decimal(0, 0);
    }
    JEWEL_ASSERT (wxs.Len() >= 1);
    if ((wxs.Len() == 1) && (*(wxs.begin()) == minus_sign))
    {
        return Decimal(0, 0);
    }

    // We first convert wxs into a canonical form in which there are no
    // thousands separators, negativity is indicated only by a minus
    // sign, and the decimal point is '.'.
    if (allow_parens && (wxs[0] == open_paren) && (wxs.Last() == close_paren))
    {
        wxs[0] = minus_sign;  // Replace left parenthesis with minus sign
        wxs.RemoveLast();  // Drop right parenthesis
    }
    wxs.Replace(thousands_sep_s, wxEmptyString);

    // We need to get the std::locale (not wxLocale) related decimal point
    // character, so that we can ensure the Decimal constructor-from-string
    // sees that appropriate decimal point character.
    locale const gloc;  // global locale
    char const spot_char = use_facet<numpunct<char> >(gloc).decimal_point();
    char const spot_str[] = { spot_char, '\0' };
    wxs.Replace(decimal_point_s, wxString(spot_str));

    string const s = wx_to_std8(wxs);
    Decimal const ret(s);
    return ret;
}
Example #22
0
void TGraphScale::DrawMark ( wxDC &dc , float p , wxRect &ir , wxString text , bool big )
	{
	int x , y , z ;
 	if ( horizontal )
 		{
    	x = GetRealCoord ( p , ir ) ;
    	y = ir.y + ir.height / 2 ;
    	z = big ? 0 : ir.height / 4 ;
    	if ( x < ir.x || x > ir.GetRight() ) return ;
 		}
 	else
  		{
    	x = ir.x + ir.width / 2 ;
    	y = GetRealCoord ( p , ir ) ;
    	z = big ? 0 : ir.width / 4 ;
    	if ( y < ir.y || y > ir.GetBottom() ) return ;
    	}        
   
	while ( text.Last() == '0' ) text = text.Left ( text.length() - 1 ) ;
   while ( text.Last() == '.' ) text = text.Left ( text.length() - 1 ) ;
   	
   int tw , th ;
   dc.GetTextExtent ( text , &tw , &th ) ;
   if ( horizontal )
   	{
	    if ( left ) dc.DrawLine ( x , y-z , x , ir.y ) ;
	    else dc.DrawLine ( x , y+z , x , ir.GetBottom() ) ;
	    x -= tw / 2 ;
	    y = left ? ir.GetBottom() - th : ir.y ;
   	}
   else
    	{
	    if ( left ) dc.DrawLine ( ir.x , y , x-z , y ) ;
	    else dc.DrawLine ( x+z , y , ir.GetRight() , y ) ;
	    y -= th / 2 ;
	    x = left ? ir.GetRight() - tw : ir.x ;
     	}        

   if ( big ) dc.DrawText ( text , x , y ) ;
	}
Example #23
0
int GetSection(wxString& s)
{
    int i, f;
    long r = -1;
    i = s.First('[');
    f = s.Last(']');
    if (f > i)
    {
        s = s.Mid((i + 1), (f - i - 1));
        if (s.IsNumber())
            s.ToLong(&r);
        else
            r = -1;
    }
    return ((int) r);
}
Example #24
0
    bool CheckString(CatalogItemPtr item, const wxString& source, const wxString& translation) override
    {
        if (u_isspace(source[0]) && !u_isspace(translation[0]))
        {
            item->SetIssue(CatalogItem::Issue::Warning, _(L"The translation doesn’t start with a space."));
            return true;
        }

        if (!u_isspace(source[0]) && u_isspace(translation[0]))
        {
            item->SetIssue(CatalogItem::Issue::Warning, _(L"The translation starts with a space, but the source text doesn’t."));
            return true;
        }

        if (source.Last() == '\n' && translation.Last() != '\n')
        {
            item->SetIssue(CatalogItem::Issue::Warning, _(L"The translation is missing a newline at the end."));
            return true;
        }

        if (source.Last() != '\n' && translation.Last() == '\n')
        {
            item->SetIssue(CatalogItem::Issue::Warning, _(L"The translation ends with a newline, but the source text doesn’t."));
            return true;
        }

        if (u_isspace(source.Last()) && !u_isspace(translation.Last()))
        {
            item->SetIssue(CatalogItem::Issue::Warning, _(L"The translation is missing a space at the end."));
            return true;
        }

        if (!u_isspace(source.Last()) && u_isspace(translation.Last()))
        {
            item->SetIssue(CatalogItem::Issue::Warning, _(L"The translation ends with a space, but the source text doesn’t."));
            return true;
        }

        return false;
    }
/* Remove trailing 0 from a string containing a converted float number.
 * the trailing 0 are removed if the mantissa has more
 * than aTrailingZeroAllowed digits and some trailing 0
 */
void StripTrailingZeros( wxString& aStringValue, unsigned aTrailingZeroAllowed )
{
    struct lconv * lc = localeconv();
    char sep = lc->decimal_point[0];
    unsigned sep_pos = aStringValue.Find( sep );

    if( sep_pos > 0 )
    {
        // We want to keep at least aTrailingZeroAllowed digits after the separator
        unsigned min_len = sep_pos + aTrailingZeroAllowed + 1;

        while( aStringValue.Len() > min_len )
        {
            if( aStringValue.Last() == '0' )
                aStringValue.RemoveLast();
            else
                break;
        }
    }
}
Example #26
0
void CLocalListView::DisplayShares(wxString computer)
{
	SHARE_INFO_1* pShareInfo = 0;

	DWORD read, total;
	DWORD resume_handle = 0;

	if (computer.Last() == '\\')
		computer.RemoveLast();

	int j = m_fileData.size();
	int res = 0;
	do
	{
		const wxWX2WCbuf buf = computer.wc_str(wxConvLocal);
		res = NetShareEnum((wchar_t*)(const wchar_t*)buf, 1, (LPBYTE*)&pShareInfo, MAX_PREFERRED_LENGTH, &read, &total, &resume_handle);

		if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
			break;

		SHARE_INFO_1* p = pShareInfo;
		for (unsigned int i = 0; i < read; i++, p++)
		{
			if (p->shi1_type != STYPE_DISKTREE)
				continue;

			t_fileData data;
			data.name = p->shi1_netname;
			data.dir = true;
			data.icon = -2;
			data.size = -1;
			data.hasTime = false;

			m_fileData.push_back(data);
			m_indexMapping.push_back(j++);
		}

		NetApiBufferFree(pShareInfo);
	}
	while (res == ERROR_MORE_DATA);
}
bool Model_Report::PrepareSQL(wxString& sql, std::map <wxString, wxString>& rep_params)
{
    sql.Trim();
    if (sql.empty()) return false;
    if (sql.Last() != ';') sql += ';';

    for (const auto& entry : SqlPlaceHolders())
    {
        wxString value;
        int pos = sql.Lower().Find(entry.label);
        size_t len = wxString(entry.label).size();

        if (pos != wxNOT_FOUND)
        {
            value = entry.def_value;

            const auto w = wxWindow::FindWindowById(entry.ID);
            //const auto name = w->GetClassInfo()->GetClassName();
            if (w && entry.type == "wxDatePickerCtrl")
            {
                    wxDatePickerCtrl* date = static_cast<wxDatePickerCtrl*>(w);
                    value = date->GetValue().FormatISODate();
            }
            else if (w && entry.type == "wxChoice")
            {
                    wxChoice* year = static_cast<wxChoice*>(w);
                    value = year->GetStringSelection();
            }

            rep_params[entry.label.Mid(1)] = value;

            while (pos != wxNOT_FOUND)
            {
                sql.replace(pos, len, value);
                pos = sql.Lower().Find(entry.label);
            }
        }
    }

    return true;
}
Example #28
0
bool wxGenericFileCtrl::SetPath( const wxString& path )
{
    wxString dir, fn, ext;
    wxFileName::SplitPath(path, &dir, &fn, &ext);

    if ( !dir.empty() && !wxFileName::DirExists(dir) )
        return false;

    m_dir = dir;
    m_fileName = fn;
    if ( !ext.empty() || path.Last() == '.' )
    {
        m_fileName += wxT( "." );
        m_fileName += ext;
    }

    SetDirectory( m_dir );
    SetFilename( m_fileName );

    return true;
}
Example #29
0
/* static */
wxProtocolError wxProtocol::ReadLine(wxSocketBase *sock, wxString& result)
{
    static const int LINE_BUF = 4095;

    result.clear();

    wxCharBuffer buf(LINE_BUF);
    char *pBuf = buf.data();
    while ( sock->WaitForRead() )
    {
        // peek at the socket to see if there is a CRLF
        sock->Peek(pBuf, LINE_BUF);

        size_t nRead = sock->LastCount();
        if ( !nRead && sock->Error() )
            return wxPROTO_NETERR;

        // look for "\r\n" paying attention to a special case: "\r\n" could
        // have been split by buffer boundary, so check also for \r at the end
        // of the last chunk and \n at the beginning of this one
        pBuf[nRead] = '\0';
        const char *eol = strchr(pBuf, '\n');

        // if we found '\n', is there a '\r' as well?
        if ( eol )
        {
            if ( eol == pBuf )
            {
                // check for case of "\r\n" being split
                if ( result.empty() || result.Last() != _T('\r') )
                {
                    // ignore the stray '\n'
                    eol = NULL;
                }
                //else: ok, got real EOL

                // read just this '\n' and restart
                nRead = 1;
            }
            else // '\n' in the middle of the buffer
            {
                // in any case, read everything up to and including '\n'
                nRead = eol - pBuf + 1;

                if ( eol[-1] != '\r' )
                {
                    // as above, simply ignore stray '\n'
                    eol = NULL;
                }
            }
        }

        sock->Read(pBuf, nRead);
        if ( sock->LastCount() != nRead )
            return wxPROTO_NETERR;

        pBuf[nRead] = '\0';
        result += wxString::FromAscii(pBuf);

        if ( eol )
        {
            // remove trailing "\r\n"
            result.RemoveLast(2);

            return wxPROTO_NOERR;
        }
    }

    return wxPROTO_NETERR;
}
Example #30
0
enum CLocalFileSystem::local_fileType CLocalFileSystem::GetFileInfo(const wxString& path, bool &isLink, wxLongLong* size, CDateTime* modificationTime, int *mode)
{
#ifdef __WXMSW__
	if (path.Last() == wxFileName::GetPathSeparator() && path != wxFileName::GetPathSeparator()) {
		wxString tmp = path;
		tmp.RemoveLast();
		return GetFileInfo(tmp, isLink, size, modificationTime, mode);
	}

	isLink = false;

	WIN32_FILE_ATTRIBUTE_DATA attributes;
	BOOL result = GetFileAttributesEx(path, GetFileExInfoStandard, &attributes);
	if (!result) {
		if (size)
			*size = -1;
		if (mode)
			*mode = 0;
		if (modificationTime)
			*modificationTime = CDateTime();
		return unknown;
	}

	bool is_dir = (attributes.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0;

	if (attributes.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) {
		isLink = true;

		HANDLE hFile = is_dir ? INVALID_HANDLE_VALUE : CreateFile(path, FILE_READ_ATTRIBUTES | FILE_READ_EA, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
		if (hFile != INVALID_HANDLE_VALUE) {
			BY_HANDLE_FILE_INFORMATION info{};
			int ret = GetFileInformationByHandle(hFile, &info);
			CloseHandle(hFile);
			if (ret != 0 && !(info.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) {

				if (modificationTime) {
					if (!ConvertFileTimeToCDateTime(*modificationTime, info.ftLastWriteTime))
						ConvertFileTimeToCDateTime(*modificationTime, info.ftCreationTime);
				}

				if (mode)
					*mode = (int)info.dwFileAttributes;

				if (info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
					if (size)
						*size = -1;
					return dir;
				}

				if (size)
					*size = wxLongLong(info.nFileSizeHigh, info.nFileSizeLow);

				return file;
			}
		}

		if (size)
			*size = -1;
		if (mode)
			*mode = 0;
		if (modificationTime)
			*modificationTime = CDateTime();
		return is_dir ? dir : unknown;
	}

	if (modificationTime) {
		if (!ConvertFileTimeToCDateTime(*modificationTime, attributes.ftLastWriteTime))
			ConvertFileTimeToCDateTime(*modificationTime, attributes.ftCreationTime);
	}

	if (mode)
		*mode = (int)attributes.dwFileAttributes;

	if (is_dir) {
		if (size)
			*size = -1;
		return dir;
	}
	else {
		if (size)
			*size = wxLongLong(attributes.nFileSizeHigh, attributes.nFileSizeLow);
		return file;
	}
#else
	if (path.Last() == '/' && path != _T("/"))
	{
		wxString tmp = path;
		tmp.RemoveLast();
		return GetFileInfo(tmp, isLink, size, modificationTime, mode);
	}

	const wxCharBuffer p = path.fn_str();
	return GetFileInfo((const char*)p, isLink, size, modificationTime, mode);
#endif
}