Exemplo n.º 1
0
void CManageTagsDlg::OnBnClickedManageTagsImportBtn()
{
	CFileDialog lDlg(TRUE, _T("*.csv"),NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Comma Delimited ( *.csv)|*.csv||"));
	if(lDlg.DoModal() == IDOK)
	{
		CString lFileName = lDlg.GetPathName();
		CStdioFile lFile(lFileName, CFile::modeRead | CFile::typeText);
		CString lLine;
		int lNumReadStr;
//		CAddMultipleTagsDlg lAddMultipleTagsDlg;
		do
		{
			lNumReadStr = lFile.ReadString(lLine);
			if(lLine.GetLength() > 0)
			{
		//		lLine.Remove(' ');
				if(m_ManageTagsList.FindString(-1, lLine) == LB_ERR)
					m_ManageTagsList.AddString(lLine);
			}
		}while(lNumReadStr);


		//http://www.experts-exchange.com/Programming/Languages/CPP/Q_22020832.html
	//	AfxMessageBox(_T("Not supported yet"));
	}
	UpdateUI();
}
Exemplo n.º 2
0
    static bool compare_files_internal(const char* filename_1, const char* filename_2)
    {
        std::ifstream lFile(filename_1, std::ios::in | std::ios::binary);
        std::ifstream rFile(filename_2, std::ios::in | std::ios::binary);


        if(!lFile.good() || !rFile.good())
        {
            return false;
        }

        std::streamsize lReadBytesCount = 0;
        std::streamsize rReadBytesCount = 0;

        const int bufferSize = 100;
        char p_lBuffer[bufferSize];
        char p_rBuffer[bufferSize];

        do {
            lFile.read(p_lBuffer, bufferSize);
            rFile.read(p_rBuffer, bufferSize);
            lReadBytesCount = lFile.gcount();
            rReadBytesCount = rFile.gcount();

            if (lReadBytesCount != rReadBytesCount || std::memcmp(p_lBuffer, p_rBuffer, lReadBytesCount) != 0)
            {
                return false;
            }
        } while (lFile.good() || rFile.good());

        return true;
    }
Exemplo n.º 3
0
/// helper function to test writing into output file
bool isFilesEqual(const char* lFilePath, const char* rFilePath)
{
	std::ifstream lFile(lFilePath, std::ios::in | std::ios::binary);
	std::ifstream rFile(rFilePath, std::ios::in | std::ios::binary);

	if (!lFile.good() || !rFile.good())
		return false;

	std::streamsize lReadBytesCount = 0;
	std::streamsize rReadBytesCount = 0;

	int bufferSize = 8192;
	char* p_lBuffer = new char[bufferSize];
	char* p_rBuffer = new char[bufferSize];

	do {
		lFile.read(p_lBuffer, bufferSize);
		rFile.read(p_rBuffer, bufferSize);
		lReadBytesCount = lFile.gcount();
		rReadBytesCount = rFile.gcount();

		if (lReadBytesCount != rReadBytesCount || std::memcmp(p_lBuffer, p_rBuffer, (size_t)lReadBytesCount) != 0)
		{
			delete[] p_lBuffer;
			delete[] p_rBuffer;

			return false;
		}
	} while (lFile.good() || rFile.good());

	delete[] p_lBuffer;
	delete[] p_rBuffer;

	return true;
}
Exemplo n.º 4
0
void Backend::log(QString line){
  QFile lFile(logFile);
  lFile.open(QIODevice::Append);
  QTextStream out(&lFile);
  out << line << "\n";
  lFile.close();
}
Exemplo n.º 5
0
bool MainWindow::setFileContent(const QString &pFileName, const QString &pContent)
{
	QFile lFile(pFileName);
	if(lFile.open(QFile::WriteOnly | QFile::Text))
		return (lFile.write(pContent.toAscii())==pContent.size());

	return false;
}
Exemplo n.º 6
0
QString MainWindow::fileContent(const QString &pFileName)
{
	QFile lFile(pFileName);
	if(lFile.open(QFile::ReadOnly | QFile::Text))
		return lFile.readAll();

	return "";
}
Exemplo n.º 7
0
void StorageAccess::insertInCache(QString const & pCacheString, QByteArray const & pData)
{
	if (pData.isEmpty())
		return;

	QFile lFile(mStorageCache.filePath(pCacheString));
	lFile.open(QFile::WriteOnly | QFile::Truncate);
	lFile.write(pData);
	lFile.close();
}
Exemplo n.º 8
0
bool StorageAccess::fromCache(QString const & pCacheString, QByteArray & pData) const
{
	QFile lFile(mStorageCache.filePath(pCacheString));
	if (!lFile.exists())
		return false;

	lFile.open(QFile::ReadOnly | QFile::Unbuffered);
	pData = lFile.readAll();
	lFile.close();

	return !pData.isEmpty();
}
Exemplo n.º 9
0
void Installer::initInstall()
{
    // load languages
    QString langCode;
    QString curLang;
    curLang = "en_US";
    bool foundLang = false;
    comboLanguage->clear();
    languages = Scripts::Backend::languages();
    if ( QFile::exists("/var/.wizardlang") ) {
      QFile lFile("/var/.wizardlang");
      if ( lFile.open(QIODevice::ReadOnly | QIODevice::Text) ) {
         curLang = lFile.readLine().simplified();
         lFile.close();
      } 
    } 

    qDebug() << curLang;

    // Now set languages
    for (int i=0; i < languages.count(); ++i) {
        QString languageStr = languages.at(i);
        QString language = languageStr.split("-").at(0);
        comboLanguage->addItem(language.trimmed());
    
        // Grab the language code
        langCode = languageStr;
        langCode.truncate(langCode.lastIndexOf(")"));
        langCode.remove(0, langCode.lastIndexOf("(") + 1);
        if ( curLang == langCode ) {
          comboLanguage->setCurrentIndex(i);
          foundLang = true;
        }
    }

    // If we found a language to default to
    if ( foundLang )
      slotChangeLanguage();

    connect(comboLanguage, SIGNAL(currentIndexChanged(QString)), this, SLOT(slotChangeLanguage()));
}
Exemplo n.º 10
0
// TODO: Tono full support of CSV files based on next link:
//http://en.wikipedia.org/wiki/Comma-separated_values
void CManageTagsDlg::OnBnClickedManageTagsExportBtn()
{
	CFileDialog lDlg(FALSE, _T("*.csv"),NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("Comma Delimited ( *.csv)|*.csv||"));
	if(lDlg.DoModal() == IDOK)
	{
		CString lTagsInDlg, lTagName;
		int lTagsCount = m_ManageTagsList.GetCount();
		for(int i = 0; i<lTagsCount; i++)
		{	
			m_ManageTagsList.GetText(i, lTagName);
			if(i == 0)
				lTagsInDlg = lTagName;
			else
				lTagsInDlg = lTagsInDlg + _T("\n") + lTagName;
		}
		CString lFileName = lDlg.GetPathName();
		CStdioFile lFile(lFileName, CFile::modeReadWrite | CFile::modeCreate | CFile::typeText);
		lFile.WriteString(lTagsInDlg);
		lFile.Flush();
		lFile.Close();
	}
	UpdateUI();
}
Exemplo n.º 11
0
void CDownloadDlg::DownloadThread()
{
    // Where should we try to put the file
    CString csFileName;
    // Extract file name from URL
    int nLastSlash = m_csSourceUrl.ReverseFind((TCHAR) '/');
    // That's our file name, in the given directory
    csFileName = m_csSourceUrl.Mid(nLastSlash + 1);
    m_csTargetPath = m_csTargetPath + csFileName;

    bool bFileError = false;

    LInternet lInternet;
    DWORD dwSysErr = 0;
    LURESULT lr = lInternet.OpenUrl(m_csSourceUrl, &dwSysErr);
    DWORD dwLength = 0;

    // Save the start time of the transfer
    m_ttStartTime = time(NULL);
    // Check length of download
    if (S_OK == lr)
    {
        DWORD dwLengthFromHeader = 0;
        lr = lInternet.GetLength(&dwLengthFromHeader);

        if (S_OK == lr)
            m_dwDownloadSize = dwLengthFromHeader;
        else
        {
            // try again with a direct connection;
            // maybe a problematic proxy is activated (ie in imc)

            lInternet.Close();

            lr = lInternet.OpenUrl(m_csSourceUrl, &dwSysErr, true);

            if (S_OK == lr)
            {
                lr = lInternet.GetLength(&dwLengthFromHeader);
                if (S_OK == lr)
                    m_dwDownloadSize = dwLengthFromHeader;
            }
            // else m_dwDownloadSize keeps the initial value
            // but not being able to determine the size is bad: the error is not reset
        }
    }

    if (S_OK == lr)
        UpdateProgress(0);

    LFile lFile(m_csTargetPath);
    if (S_OK == lr)
    {
        lr = lFile.Create(LFILE_TYPE_BINARY);
        if (S_OK != lr)
            bFileError = true;
    }

    if (S_OK == lr)
    {
        const DWORD dwBufSize = 16384;

        DWORD dwBytesToRead = dwBufSize;
        DWORD dwBytesRead = 1;
        DWORD dwTotalBytesRead = 0;
        char pBuffer[dwBufSize];
        while (dwBytesRead > 0 && !m_bCancelRequested)
        {
            lr = lInternet.Read(pBuffer, dwBytesToRead, &dwBytesRead, NULL);
            if (S_OK == lr)
            {
                if (dwBytesRead > 0)
                {
                    dwTotalBytesRead += dwBytesRead;

                    lr = lFile.WriteRaw(pBuffer, dwBytesRead);
                    if (S_OK == lr)
                    {
                        UpdateProgress(dwTotalBytesRead);
                    }
                    else
                    {
                        bFileError = true;
                        dwBytesRead = 0;
                    }
                }
            }
        }
    }
    lFile.Close();

    if (S_OK == lr && !m_bCancelRequested)
    {
        m_bDownloadSuccessful = true;
    }
    else if (!m_bCancelRequested)
    {
        // Assemble some error message
        CString csMsg;
        if (bFileError)
            csMsg.LoadString(IDS_ERR_WRITEFILE);
        else
        {
            if (LINTERNET_ERR_NOTFOUND == lr)
                csMsg.LoadString(IDS_ERR_PATCHNOTFOUND);
            else
                csMsg.LoadString(IDS_ERR_READPATCH);
        }

        MessageBox(csMsg, _T("LECTURNITY Auto-Update"), MB_OK | MB_ICONWARNING);

        m_bCancelRequested = true;
    }

    if (!m_bDownloadSuccessful)
        lFile.Delete();

    m_bDownloadThreadFinished = true;
}