Example #1
0
void rab::WriteRegistryFiles( Options const& options, Config const& config, 
	FolderInfo::FileInfos_t const& fileInfos, dung::Action::Enum action, Path_t const& relativePath, OutputContext& output )
{
	for( FolderInfo::FileInfos_t::const_iterator i = fileInfos.begin(); i != fileInfos.end(); ++i )
	{
		FileInfo const& fileInfo = **i;
		dung::Action::Enum fileAction = fileInfo.isDifferent ? dung::Action::APPLY_DIFF : action;

		if( fileAction == dung::Action::NEW && config.newFileLimit > 0 && fileInfo.newSize >= config.newFileLimit )
			fileAction = dung::Action::NEW_BUT_NOT_INCLUDED;

		if( fileAction == dung::Action::NEW && MatchName( config.newOverrideFiles_regex, fileInfo.name ) )
			fileAction = dung::Action::OVERRIDE;

		if( fileAction == dung::Action::DELETE && MatchName( config.oldPreserveRemoved_regex, fileInfo.name ) )
			fileAction = dung::Action::NONE;

		if( fileAction == dung::Action::APPLY_DIFF && MatchName( config.oldSkipChanged_regex, fileInfo.name ) )
			fileAction = dung::Action::NONE;

		output.stream << _T("file") << endl;
		output.stream << _T("{") << endl;

		output.stream << _T("\t") << _T("action=") << dung::ActionToString(fileAction) << endl;

		if( fileAction != dung::Action::DELETE && fileAction != dung::Action::NONE )
		{
			output.stream << _T("\t") << _T("new_path=") << quote << GenericString( relativePath / fileInfo.name ) << quote << endl;
			output.stream << _T("\t") << _T("new_size=") << fileInfo.newSize << endl;
			output.stream << _T("\t") << _T("new_sha1=") << quote << dung::SHA1_TO_TSTRING(fileInfo.newSha1) << quote << endl;
		}

		if( fileAction != dung::Action::NEW && fileAction != dung::Action::OVERRIDE && fileAction != dung::Action::NEW_BUT_NOT_INCLUDED )
		{
			output.stream << _T("\t") << _T("old_path=") << quote << GenericString( relativePath / fileInfo.name ) << quote << endl;
			output.stream << _T("\t") << _T("old_size=") << fileInfo.oldSize << endl;
			output.stream << _T("\t") << _T("old_sha1=") << quote << dung::SHA1_TO_TSTRING(fileInfo.oldSha1) << quote << endl;
		}

		if( fileAction == dung::Action::APPLY_DIFF )
		{
			output.stream << _T("\t") << _T("diff_path=") << quote << GenericString( relativePath / DiffFileName(fileInfo.name, config) ) << quote << endl;
			output.stream << _T("\t") << _T("diff_method=") << fileInfo.diffMethod << endl;
		}

		output.stream << _T("}") << endl;
	}
}
		ContactInformation ExtractContactInformation(std::vector<std::string> inputTextCollection)
		{
			ContactInformation contact;
			contact.Email = MatchEmail(inputTextCollection);
			contact.Name = MatchName(inputTextCollection, contact.Email);
			contact.Phone = MatchPhone(inputTextCollection);
			return contact;
		}
Example #3
0
dung::DiffEncoderExternal_i* rab::DiffEncoders::FindExternalEncoder( String_t const& fileName, DiffMethod_t& encoderName ) const
{
	for( DiffExternalEncoders_t::const_iterator i = m_diffEncodersExternal.begin(); i != m_diffEncodersExternal.end(); ++i )
	{
		ExternalEncoderEntry const& encoderEntry = **i;
		if( MatchName( encoderEntry.m_packFiles, fileName ) )
		{
			encoderName = encoderEntry.m_encoderName;
			return encoderEntry.m_pDiffEncoder;
		}
	}

	return NULL;
}
Example #4
0
bool rab::BuildDiffFile( Options const& options, Config const& config, DiffEncoders const& diffEncoders,
	Path_t const& relativePath, PackageOutput_t& package, LogOutput_t& out, FileInfo& fileInfo )
{
	Path_t fullNew = options.pathToNew / relativePath / fileInfo.name;
	Path_t fullOld = options.pathToOld / relativePath / fileInfo.name;
	Path_t relativeTemp = relativePath / DiffFileName(fileInfo.name, config);

	dung::MemoryBlock oldFile;
	if( !ReadWholeFile( fullOld.wstring(), oldFile ) )
	{
		out << "Can't read file " << FileString(fullOld) << std::endl;
		return false;
	}
	
	dung::SHA1Compute( oldFile.pBlock, oldFile.size, fileInfo.oldSha1 );
	fileInfo.oldSize = oldFile.size;

	if( MatchName( config.oldSkipChanged_regex, fileInfo.name ) )
		return true;

	dung::MemoryBlock newFile;
	if( !ReadWholeFile( fullNew.wstring(), newFile ) )
	{
		out << "Can't read file " << FileString(fullNew) << std::endl;
		return false;
	}

	dung::SHA1Compute( newFile.pBlock, newFile.size, fileInfo.newSha1 );
	fileInfo.newSize = newFile.size;

	bool result = true;

	if( fileInfo.newSha1 != fileInfo.oldSha1 )
	{
		fileInfo.isDifferent = true;
		
		result &= CreateDiffFile( options, diffEncoders, fileInfo, fullNew, fullOld, relativeTemp, newFile, oldFile, package, out );
	}
	else
		fileInfo.isDifferent = false;

	return result;
}
Example #5
0
/** \brief Get an entry from this collection.
 *
 * This function returns a shared pointer to a FileEntry object for
 * the entry with the specified name. To ignore the path part of the
 * filename while searching for a match, specify FileCollection::IGNORE
 * as the second argument.
 *
 * \note
 * The collection must be valid or the function raises an exception.
 *
 * \param[in] name  A string containing the name of the entry to get.
 * \param[in] matchpath  Speficy MatchPath::MATCH, if the path should match
 *                       as well, specify MatchPath::IGNORE, if the path
 *                       should be ignored.
 *
 * \return A shared pointer to the found entry. The returned pointer
 *         is null if no entry is found.
 *
 * \sa mustBeValid()
 */
FileEntry::pointer_t FileCollection::getEntry(std::string const& name, MatchPath matchpath) const
{
    // make sure the entries were loaded if necessary
    entries();

    mustBeValid();

    FileEntry::vector_t::const_iterator iter;
    if(matchpath == MatchPath::MATCH)
    {
        iter = std::find_if(m_entries.begin(), m_entries.end(), MatchName(name));
    }
    else
    {
        iter = std::find_if(m_entries.begin(), m_entries.end(), MatchFileName(name));
    }

    return iter == m_entries.end() ? FileEntry::pointer_t() : *iter;
}
Example #6
0
VOID TFileBase::SearchFile (PSZ pszFile)
{
   USHORT i, Readed, RetVal = FALSE;
   ULONG Crc;
   NAMESORT ns, *pns;
   FILEDATA fileData;
   FILEINDEX *fileIndex;

   if (List == NULL)
      List = new TCollection;
   fileIndex = (FILEINDEX *)malloc (sizeof (FILEINDEX) * MAX_INDEX);
   strlwr (pszFile);

   if (List != NULL && fileIndex != NULL) {
      List->Clear ();
      Crc = StringCrc32 (szArea, 0xFFFFFFFFL);

      if (fdDat != -1 && fdIdx != -1) {
         lseek (fdIdx, 0L, SEEK_SET);
         while ((Readed = (USHORT)read (fdIdx, fileIndex, sizeof (FILEINDEX) * MAX_INDEX)) > 0) {
            Readed /= sizeof (FILEINDEX);
            for (i = 0; i < Readed; i++) {
               if (!(fileIndex[i].Flags & (FILE_DELETED|FILE_UNAPPROVED)) && (szArea[0] == '\0' || fileIndex[i].Area == Crc)) {
                  lseek (fdDat, fileIndex[i].Offset, SEEK_SET);
                  read (fdDat, &fileData, sizeof (fileData));

                  if (fileData.Id == FILEBASE_ID) {
                     RetVal = FALSE;
                     if (MatchName (fileIndex[i].Name, pszFile) == TRUE) {
                        fileIndex[i].Name[sizeof (fileIndex[i].Name) - 1] = '\0';
                        strcpy (ns.Name, fileIndex[i].Name);
                        ns.Position = fileIndex[i].Offset;
                        if ((pns = (NAMESORT *)List->First ()) != NULL) {
                           if (strcmp (pns->Name, ns.Name) > 0) {
                              List->Insert (&ns, sizeof (ns));
                              List->Insert (pns, sizeof (ns));
                              List->First ();
                              List->Remove ();
                              RetVal = TRUE;
                           }
                           if (RetVal == FALSE)
                              do {
                                 if (strcmp (pns->Name, ns.Name) > 0) {
                                    List->Previous ();
                                    List->Insert (&ns, sizeof (ns));
                                    RetVal = TRUE;
                                 }
                              } while (RetVal == FALSE && (pns = (NAMESORT *)List->Next ()) != NULL);
                        }

                        if (RetVal == FALSE)
                           List->Add (&ns, sizeof (ns));
                     }
                  }
               }
            }
         }
      }
   }

   if (fileIndex != NULL)
      free (fileIndex);
}
Example #7
0
USHORT TFileBase::Next (PSZ pszSearch)
{
   USHORT fRet = FALSE, i, r, w;
   CHAR szTemp[80], szLine[80];
   ULONG ulCrc;
   NAMESORT *ns;
   FILEDATA fileData;
   FILEINDEX fileIndex;
   struct tm *ftm;

   if (List == NULL && fdDat != -1) {
      ulCrc = StringCrc32 (szArea, 0xFFFFFFFFL);

      while (read (fdIdx, &fileIndex, sizeof (fileIndex)) == sizeof (fileIndex)) {
         if (fileIndex.Flags & FILE_DELETED)
            continue;
         if (szArea[0] == '\0' || fileIndex.Area == ulCrc) {
            fRet = TRUE;
            if (pszSearch != NULL)
               fRet = MatchName (fileIndex.Name, pszSearch);
            if (fRet == TRUE) {
               lseek (fdDat, fileIndex.Offset, SEEK_SET);
               break;
            }
         }
      }
   }
   else if (List != NULL && (ns = (NAMESORT *)List->Next ()) != NULL) {
      lseek (fdDat, ns->Position, SEEK_SET);
      fRet = TRUE;
   }

   if (fRet == TRUE) {
      read (fdDat, &fileData, sizeof (fileData));

      fRet = FALSE;
      if (fileData.Id == FILEBASE_ID) {
         Clear ();
         fileData.Area[sizeof (fileData.Area) - 1] = '\0';
         fileData.Name[sizeof (fileData.Name) - 1] = '\0';
         fileData.Complete[sizeof (fileData.Complete) - 1] = '\0';
         fileData.Keyword[sizeof (fileData.Keyword) - 1] = '\0';

         strcpy (Area, fileData.Area);
         strcpy (Name, fileData.Name);
         strcpy (Complete, fileData.Complete);
         strcpy (Keyword, fileData.Keyword);
         if (fileData.Description != 0) {
            w = 0;
            do {
               if ((r = (USHORT)sizeof (szTemp)) > fileData.Description)
                  r = fileData.Description;
               r = (USHORT)read (fdDat, szTemp, r);
               for (i = 0; i < r; i++) {
                  if (szTemp[i] == '\r') {
                     szLine[w++] = '\0';
                     Description->Add (szLine, w);
                     w = 0;
                  }
                  else if (szTemp[i] != '\n')
                     szLine[w++] = szTemp[i];
               }
               fileData.Description -= r;
            } while (fileData.Description > 0);
            if (w > 0) {
               szLine[w++] = '\0';
               Description->Add (szLine, w);
            }
         }
         if (fileData.Uploader != 0) {
            fUploader = TRUE;
            pszMemUploader = Uploader = (PSZ)malloc (fileData.Uploader);
            read (fdDat, Uploader, fileData.Uploader);
         }
         Size = fileData.Size;
         DlTimes = fileData.DlTimes;
         FileDate = fileData.FileDate;
         ftm = localtime ((time_t *)&fileData.FileDate);
         Date.Day = (UCHAR)ftm->tm_mday;
         Date.Month = (UCHAR)(ftm->tm_mon + 1);
         Date.Year = (USHORT)(ftm->tm_year + 1900);
         Date.Hour = (UCHAR)ftm->tm_hour;
         Date.Minute = (UCHAR)ftm->tm_min;
         UploadDate = fileData.UploadDate;
         ftm = localtime ((time_t *)&fileData.UploadDate);
         UplDate.Day = (UCHAR)ftm->tm_mday;
         UplDate.Month = (UCHAR)(ftm->tm_mon + 1);
         UplDate.Year = (USHORT)(ftm->tm_year + 1900);
         UplDate.Hour = (UCHAR)ftm->tm_hour;
         UplDate.Minute = (UCHAR)ftm->tm_min;
         Cost = fileData.Cost;
         Password = fileData.Password;
         Level = fileData.Level;
         AccessFlags = fileData.AccessFlags;
         DenyFlags = fileData.DenyFlags;
         Unapproved = (fileData.Flags & FILE_UNAPPROVED) ? TRUE : FALSE;
         CdRom = (fileData.Flags & FILE_CDROM) ? TRUE : FALSE;
         fRet = TRUE;
      }
   }

   return (fRet);
}
Example #8
0
static bool GlobAgainstDirectory(char *thePattern,UINT32 patternIndex,char *pathBuffer,UINT32 pathIndex,GLOBDATA *theData)
// try thePattern against all files at pathBuffer, adding each that matches completely, and calling
// move further on each one
// if there is some sort of problem, SetError, and return false
{
	DIR
		*theDirectory;
	struct dirent
		*theEntry;
	bool
		fail;
	char
		*thePath;
	UINT32
		theLength;
	UINT32
		newIndex;
	bool
		haveMatch;

	fail=false;
	if(pathBuffer[0])
	{
		thePath=pathBuffer;						// point at the passed path if one given
	}
	else
	{
		thePath="./";							// if passed path is empty, it means current directory
	}
	if((theDirectory=opendir(thePath)))			// if it does not open, assume it is because thePath did not point to something valid
	{
		while(!fail&&(theEntry=readdir(theDirectory)))
		{
			newIndex=patternIndex;
			if(theEntry->d_name[0]!='.'||thePattern[patternIndex]=='.')			// the first . must be matched exactly
			{
				if(MatchName(theEntry->d_name,thePattern,&newIndex,&haveMatch))
				{
					if(haveMatch)					// was there a match?
					{
						theLength=strlen(theEntry->d_name);
						if(pathIndex+theLength<MAXPATHLEN)	// append to path (if there's room)
						{
							strcpy(&(pathBuffer[pathIndex]),theEntry->d_name);
							if(thePattern[newIndex])		// see if there's more pattern left
							{
								fail=!MoveFurther(thePattern,newIndex,pathBuffer,pathIndex+theLength,theData);
							}
							else
							{
								fail=!AddStringToList(pathBuffer,&theData->thePaths,&theData->numPaths);
							}
						}
						else
						{
							SetError(localErrorFamily,errorMembers[PATHTOOLONG],errorDescriptions[PATHTOOLONG]);
							fail=true;
						}
					}
				}
				else
				{
					fail=true;
				}
			}
		}
		closedir(theDirectory);
	}
	return(!fail);
}
Example #9
0
static bool MatchName(char *theName,char *thePattern,UINT32 *patternIndex,bool *haveMatch)
// match theName against thePattern
// thePattern points to the start of a pattern terminated with a '\0', or a PATHSEP
// update patternIndex to point to the character that stopped the match
// if a match occurs, return true if have match
// if there is a problem SetError, and return false
{
	UINT32
		nameIndex;
	UINT32
		startPatternIndex;
	bool
		fail,
		done,
		matching;
	char
		theChar;

	fail=*haveMatch=done=false;
	matching=true;
	nameIndex=0;
	while(!done&&matching)
	{
		switch(thePattern[*patternIndex])
		{
			case '\0':				// ran out of characters of the pattern
			case PATHSEP:
				matching=(theName[nameIndex]=='\0');
				done=true;
				break;
			case '*':
				(*patternIndex)++;	// move past the *
				matching=false;
				do
				{
					startPatternIndex=*patternIndex;
					fail=!MatchName(&theName[nameIndex],thePattern,&startPatternIndex,&matching);
				}
				while(theName[nameIndex++]&&!fail&&!matching);			// recurse trying to make a match
				if(matching)
				{
					*patternIndex=startPatternIndex;
					done=true;
				}
				break;
			case '?':
				(*patternIndex)++;
				matching=(theName[nameIndex++]!='\0');
				break;
			case '[':
				(*patternIndex)++;
				if((theChar=theName[nameIndex++]))
				{
					fail=!MatchRange(theChar,thePattern,patternIndex,&matching);
				}
				else
				{
					matching=false;
				}
				break;
			case '\\':
				(*patternIndex)++;
				if((theChar=thePattern[(*patternIndex)++]))
				{
					matching=(theName[nameIndex++]==theChar);
				}
				else
				{
					SetError(localErrorFamily,errorMembers[DANGLINGQUOTE],errorDescriptions[DANGLINGQUOTE]);
					fail=true;
				}
				break;
			default:
				matching=(theName[nameIndex++]==thePattern[(*patternIndex)++]);
				break;
		}
	}
	if(!fail)
	{
		*haveMatch=matching;
	}
	return(!fail);
}