DecryptionWindow::DecryptionWindow(Market* market, QWidget *parent, QVector<QString> wordOverride) :
    QWidget(parent),
    ui(new Ui::DecryptionWindow)
{
    ui->setupUi(this);

    this->market = market;
    if (market != NULL)
    {
        QString decryptsFileName = "Decrypts " + QDateTime::currentDateTime().toString(" - MM-dd hh.mm.txt");
        decryptsFile = new QFile(decryptsFileName);
        bool ok = decryptsFile->open(QIODevice::WriteOnly | QIODevice::Text);

        if (!ok)
        {
            // We've failed to open a log file for writing. wtf.
            QMessageBox::critical(0,"Error","Unable to write user decryptions file");
            exit(EXIT_FAILURE);
        }
    }

    connect(ui->btnSubmit, SIGNAL(clicked()), this, SLOT(DoneClicked()));

    score = 0;
    if (wordOverride.count() == 0)
    {
        wordyStuff = WordList(":/dictionary")
                .Generate(MIN_DECRYPTION_LEN,MAX_DECRYPTION_LEN);
    }
    else
    {
        wordyStuff = wordOverride;
    }
    ResetTask();
}
void SparseReordering::ReadWordList(const string& filename, const string& id, SparseReorderingFeatureKey::Side side, vector<WordList>* pWordLists) {
  ifstream fh(filename.c_str());
  UTIL_THROW_IF(!fh, util::Exception, "Unable to open: " << filename);
  string line;
  pWordLists->push_back(WordList());
  pWordLists->back().first = id;
  while (getline(fh,line)) {
    //TODO: StringPiece
    const Factor* factor = FactorCollection::Instance().AddFactor(line);
    pWordLists->back().second.insert(factor);
    PreCalculateFeatureNames(pWordLists->size()-1, id, side, factor, false); 

  }
}
//********************************************************
void WordsEdit::merge_file()
{

  WordList w = WordList();
  Q3FileDialog *f = new Q3FileDialog(0,"Open",true);  
  const char *filters[] = {"words.tok","*.tok","All files (*)",NULL};
  
  f->setFilters(filters);
  f->setCaption("Open");
  f->setMode(Q3FileDialog::ExistingFile);
  f->setDir(game->dir.c_str());
  if ( f->exec() == QDialog::Accepted ) {
    if ( !f->selectedFile().isEmpty() ){
      int ret = w.read((char *)f->selectedFile().latin1());
      if(ret)return ;
      wordlist->merge(w);
      update_all();
    }
  }
  
}
Beispiel #4
0
void GenerateWordList (const CString &sDataFile, CXMLElement *pCmdLine)

//	GenerateWordList
//
//	Generate a list of unique words used in the game

{
    ALERROR error;
    int i;
    CString sError;

    //	Open the XML file

    CResourceDb Resources(sDataFile);
    if (error = Resources.Open())
    {
        printf("Unable to initialize data file.\n");
        return;
    }

    CXMLElement *pGameFile;
    if (error = Resources.LoadGameFile(&pGameFile, NULL, &sError))
    {
        printf("%s\n", sError.GetASCIIZPointer());
        return;
    }

    //	Create the context

    CSymbolTable WordList(FALSE, TRUE);
    TraverseCtx Ctx;
    Ctx.pWordList = &WordList;

    //	Recursive descent

    ParseWordList(Ctx, pGameFile);

    //	Parse all modules too

    CXMLElement *pModules = pGameFile->GetContentElementByTag(MODULES_TAG);
    if (pModules)
    {
        for (i = 0; i < pModules->GetContentElementCount(); i++)
        {
            CXMLElement *pModule = pModules->GetContentElement(i);
            CXMLElement *pModuleXML;
            if (error = Resources.LoadModule(NULL_STR, pModule->GetAttribute(FILENAME_ATTRIB), &pModuleXML, &sError))
            {
                printf("%s\n", sError.GetASCIIZPointer());
                return;
            }

            ParseWordList(Ctx, pModuleXML);
        }
    }

    //	Print out the word list

    for (i = 0; i < WordList.GetCount(); i++)
        printf("%s\n", WordList.GetKey(i).GetASCIIZPointer());
}