Example #1
0
 String
 StringParser::ExtractAddress(const String &sEMailAddress)
 //---------------------------------------------------------------------------()
 // DESCRIPTION:
 // Extracts the adress from an email address string. (the part before @)
 //---------------------------------------------------------------------------()
 {
    int iAtSign = sEMailAddress.ReverseFind(_T("@"));
    String sDomain = sEMailAddress.Mid(0, iAtSign);
    return sDomain;
 }
Example #2
0
 String
 StringParser::ExtractDomain(const String &sEMailAddress)
 //---------------------------------------------------------------------------()
 // DESCRIPTION:
 // Extracts the domain from an email address string. (the part after @)
 //---------------------------------------------------------------------------()
 {
    int iAtSign = sEMailAddress.ReverseFind(_T("@"));
    String sDomain = sEMailAddress.Mid(iAtSign+1);
    return sDomain;
 }
Example #3
0
   String
   FileUtilities::GetFilePath(const String & FileName)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Returns the path to the folder in which FileName resides.
   //---------------------------------------------------------------------------()
   {
      int iLastSlash = FileName.ReverseFind(_T("\\"));
      String Path = FileName.Mid(0, iLastSlash);

      return Path;
   }
Example #4
0
   String
   FileUtilities::GetFileNameFromFullPath(const String & sFullPath)
   //---------------------------------------------------------------------------()
   // DESCRIPTION:
   // Returns the filename in the full path.
   //---------------------------------------------------------------------------()
   {
      int iLastSlash = sFullPath.ReverseFind(_T("\\"));

      if (iLastSlash == -1)
      {
         // Path is relative.
         return sFullPath;
      }

      return sFullPath.Mid(iLastSlash + 1);
   }
Example #5
0
   bool
   FileUtilities::Copy(const String &sFrom, const String &sTo, bool bCreateMissingDirectories)
   {
      int iNumberOfTries = 0;
      const int iMaxNumberOfTries = 5;

      if (bCreateMissingDirectories)
      {
         String sToPath = sTo.Mid(0, sTo.ReverseFind(_T("\\")));
         CreateDirectoryRecursive(sToPath);
      }


      const int maxRecursions = 10000;
      for (int i = 0; i < maxRecursions; i++)
      {
         // Use classic api to copy the file
         if (::CopyFile(sFrom, sTo, FALSE) != 0)
         {
            //Copy OK
            return true;
         }

         iNumberOfTries ++;

         // We failed to delete the file. 

         if (iNumberOfTries >= iMaxNumberOfTries)
         {
            // We still couldn't copy the file. Lets give up and report in windows event log and hMailServer application log
            int iLastError = ::GetLastError();

            String sErrorMessage;
            sErrorMessage.Format(_T("Could not copy the file %s to %s. Tried 5 times without success. Windows eror code: %d (%s)"), sFrom, sTo, iLastError, Dictionary::GetWindowsErrorDescription(iLastError));
            ErrorManager::Instance()->ReportError(ErrorManager::High, 5048, "File::Copy", sErrorMessage);
            return false;
         }

         // Some other process must have locked the file.
         Sleep(1000);
      }

      assert(0); // if we get here, something is really strange...
      return false;
   }
Example #6
0
// POSIX lib files have names in form of libXXXXXX.so.ver.minver(.rel)
// so we can't simply get file extension
String CppBuilder::GetSrcType(String fn) const
{
	fn = ToLower(fn);
	String ext = GetFileExt(fn);
	if(!HasFlag("POSIX") || ext == ".so")
		return ext;
	int soPos = fn.ReverseFind(".so");
	if(soPos < 0)
		return ext;
	fn = fn.Mid(soPos + 3);
	const char *c = ~fn;
	while(*c)
	{
		if(*c != '.' && !IsDigit(*c))
			return ext;
		c++;
	}
	return ".so";
}
Example #7
0
void TopicEditor::Hyperlink(String& link, WString& text)
{
	TopicLinkDlg d;
	d.link <<= link;
	String label;
	TopicLink tl;
	int q = link.ReverseFind('#');
	if(q >= 0) {
		label = link.Mid(q + 1);
		tl = ParseTopicLink(link.Mid(0, q));
	}
	else
		tl = ParseTopicLink(link);
	if(IsNull(tl.topic)) {
		d.package.FindSetCursor(GetFileTitle(GetFileFolder(grouppath))) &&
		d.group.FindSetCursor(GetFileTitle(grouppath)) &&
		d.topic.FindSetCursor(topic.GetCurrentName());
	}
	else {
		d.package.FindSetCursor(tl.package) &&
		d.group.FindSetCursor(tl.group) &&
		d.topic.FindSetCursor(tl.topic) &&
		d.label.FindSetCursor(label);
	}
	int c = d.Run();
	if(c == IDCANCEL)
		return;
	link = ~d.link;
	if(c == IDOK)
		return;
	if(d.topic.IsCursor()) {
		String fn = AppendFileName(d.PackageGroup(d.group.GetCurrentName()),
		                           d.topic.GetCurrentName() + ".tpp");
		text = ReadTopic(LoadFile(fn)).title.ToWString();
	}
}