Exemple #1
0
static status_t ExpandFilePathWildCardsAux(const String & curDir, const String & path, Queue<String> & outputPaths, bool isSimpleFormat)
{
   const char * fs = GetFilePathSeparator();
   const int32 sepIdx = path.IndexOf(fs);
   const String firstClause  = (sepIdx >= 0) ? path.Substring(0, sepIdx) : path;
   const String restOfString = (sepIdx >= 0) ? path.Substring(sepIdx+1) : GetEmptyString();

   StringMatcher sm(firstClause, isSimpleFormat);
   Directory dir(curDir());
   if (dir.IsValid())
   {
      if (CanWildcardStringMatchMultipleValues(firstClause))
      {
         while(1)
         {
            const char * fn = dir.GetCurrentFileName();
            if (fn)
            {
               if ((strcmp(fn, ".") != 0)&&(strcmp(fn, "..") != 0)&&((fn[0] != '.')||(firstClause.StartsWith(".")))&&(sm.Match(fn)))
               {
                  const String childPath = String(dir.GetPath())+fn;
                  if (restOfString.HasChars())
                  {
                     if (ExpandFilePathWildCardsAux(childPath, restOfString, outputPaths, isSimpleFormat) != B_NO_ERROR) return B_ERROR;
                  }
                  else if (outputPaths.AddTail(childPath) != B_NO_ERROR) return B_ERROR;
               } 
               dir++;
            }
            else break;
         }
      }
      else
      {
         const String childPath = String(dir.GetPath())+firstClause;
         if (FilePathInfo(childPath()).Exists())
         {
            if (restOfString.HasChars())
            {
               if (ExpandFilePathWildCardsAux(childPath, restOfString, outputPaths, isSimpleFormat) != B_NO_ERROR) return B_ERROR;
            }
            else if (outputPaths.AddTail(childPath) != B_NO_ERROR) return B_ERROR;
         }
      }
   }
   return B_NO_ERROR;
}
void cpNewProject::onPBOk()
{
    // Get file name as enetered by the user
    QString FileName = m_LEName->text();

    // Remove any extension from file name
    QFileInfo FileInfo(FileName);
    FileName = FileInfo.baseName();
    
    // Check if we have a name
    if (FileName.size() == 0)
    {
        QMessageBox msgBox;
        msgBox.setText("Please enter a project name");
        msgBox.exec();
        return;
    }

    // Get the Destination folder
    QString Destination = m_DestinationFolder->text();
    if (Destination.size() == 0)
                     Destination = "./";

    // Cover any cononical setting such as ./ and ../ to full path
    QFileInfo FilePathInfo(Destination);
    if (FilePathInfo.canonicalFilePath().size() > 0)
        Destination = FilePathInfo.canonicalFilePath();
    
    QCharRef c = Destination[Destination.length() - 1];

    if ((c != '/') || (c != '\\')) Destination.append("/");

    // now add the filename
    Destination.append(FileName);

    // check for pre-existing project that will get replaced with this new one
    QFile fileexist(Destination +".cprj");
    if (fileexist.exists())
    {
        if (QMessageBox::question(this, "Project", "File already exists\nDo you want to continue?", QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)
            return;
    }

    emit OnSetNewProject(Destination);
    hide();
}