Example #1
0
status_t
ThemeManager::SetThemeScreenShot(int32 id, BBitmap *bitmap)
{
	FENTRY;
	status_t err;
	BMessage msg;
	BString name;
	BString themepath;
	BMessage *theme;
	
	if (id < 0)
		return EINVAL;
	theme = (BMessage *)fThemeList.ItemAt(id);
	if (!theme)
		return EINVAL;
	
	// TODO
	err = theme->FindMessage(Z_THEME_INFO_MESSAGE, &msg);
	if (err) {
		msg.MakeEmpty();
		theme->AddMessage(Z_THEME_INFO_MESSAGE, &msg);
	}
	err = ThemeLocation(id, themepath);
	if (err)
		return err;
	err = msg.FindString(Z_THEME_SCREENSHOT_FILENAME, &name);
	if (!err) {
		BPath spath(themepath.String());
		spath.Append(name.String());
		BEntry ent(spath.Path());
		if (ent.InitCheck() == B_OK)
			ent.Remove();
	}
	
	name = "screenshot.png";
	err = msg.ReplaceString(Z_THEME_SCREENSHOT_FILENAME, name);
	if (err)
		err = msg.AddString(Z_THEME_SCREENSHOT_FILENAME, name);
	if (err)
		return err;
	
	// save the BBitmap to a png
	BPath spath(themepath.String());
	spath.Append(name.String());
	BFile shotfile(spath.Path(), B_WRITE_ONLY|B_CREATE_FILE);
	if (shotfile.InitCheck() != B_OK)
		return shotfile.InitCheck();
	BTranslatorRoster *troster = BTranslatorRoster::Default();
	BBitmapStream bmstream(bitmap);
	err = troster->Translate(&bmstream, NULL, NULL, &shotfile, 'PNG '/* XXX: hack, should find by mime type */);
	if (err)
		return err;
	
	err = theme->ReplaceMessage(Z_THEME_INFO_MESSAGE, &msg);
	msg.PrintToStream();
	return err;
}
Example #2
0
int _tmain(int argc, _TCHAR* argv[])
{
	CTGitPath path;
	CString root;
	TCHAR buff[256];
	
	GetCurrentDirectory(256,buff);
	path.SetFromWin(buff);

	if(!path.HasAdminDir(&root))
	{
		printf("not in git repository\n");
		return -1;
	}

	CGitIndexList list;
	list.ReadIndex(root+_T("\\.git\\index"));

	CGitHeadFileList filelist;
	filelist.ReadHeadHash(buff);
	_tprintf(_T("update %d\n"), filelist.CheckHeadUpdate());

	git_init();
//	filelist.ReadTree();

	WIN32_FIND_DATA data;
	CString str(buff);
	str+=_T("\\*.*");
	GitStatus status;

	HANDLE handle = FindFirstFile(str,&data);
	while(FindNextFile(handle,&data))
	{
		if( _tcsnccmp(data.cFileName, _T(".."),2) ==0) 
			continue;
		if( _tcsnccmp(data.cFileName, _T("."),1) ==0 ) 
			continue;

		CString spath(buff);
		spath += _T("\\");
		spath += data.cFileName;
		CTGitPath path(spath);

		TCHAR name[100];
		int t1,t2;
		t1 = ::GetCurrentTime();
		status.GetStatusString(status.GetAllStatus(path), 100,name);
		t2 = ::GetCurrentTime();

		_tprintf(_T("%s - %s - %d\n"),data.cFileName, name, t2-t1);
		
	}

	return 0;
}
bool HttpRequestHandler::MatchAnyPattern
(const std::string &path, const std::vector<std::string> &patterns) {
  String spath(path.c_str(), path.size(), CopyString);
  for (unsigned int i = 0; i < patterns.size(); i++) {
    Variant ret = preg_match(String(patterns[i].c_str(), patterns[i].size(),
                                    CopyString),
                             spath);
    if (ret.toInt64() > 0) return true;
  }
  return false;
}
Example #4
0
void SFTWorker::finishFile()
{
	m_hFh.close();

	std::string file = m_pCurFile->getFullPath();
	gcString str("{0}", m_pCurFile->getTimeStamp());

	try
	{
		ptime t(from_iso_string(str));
		bfs::path spath(file);

		tm pt_tm = to_tm(t);
		last_write_time(spath, mktime(&pt_tm));
	}
	catch (...)
	{
		Warning(gcString("Failed to change {0} time stamp to {1}.\n", m_pCurFile->getName(), str));
	}

	safe_delete(m_pBzs);

	std::string hash = "Failed to generate hash";

#ifdef NIX
	//struct stat s;
	bool isWinExe = false;
	
	if (file.size() > 4)
	{
		std::string lastFour(file.end() - 4, file.end());
		std::transform(lastFour.begin(), lastFour.end(), lastFour.begin(), ::toupper);
		if (lastFour == ".EXE")
			isWinExe = true;
	}
	
	//( && stat(file.c_str(), &s) == 0) 
	
	bool isExecutable = HasAnyFlags(m_pCurFile->getFlags(), MCFCore::MCFFileI::FLAG_XECUTABLE);

	if (isExecutable || isWinExe)
		chmod(file.c_str(), (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH));
#endif

	if (m_pCurFile->isZeroSize() || m_pCurFile->hashCheckFile(&hash))
	{
		m_pCT->endTask(m_uiId, BaseMCFThread::SF_STATUS_COMPLETE);
	}
	else
	{
		Warning(gcString("Hash check failed for file [{0}]: Cur: {1} !=  Should: {2}\n", m_pCurFile->getName(), hash, m_pCurFile->getCsum()));
		m_pCT->endTask(m_uiId, BaseMCFThread::SF_STATUS_HASHMISSMATCH);
	}
}
Example #5
0
void EQKAnalyzer::MKDirFor( const std::string& path, bool isdir ) const {
	if( path.empty() ) return;
	std::stringstream spath(path);
	std::vector<std::string> dirs;
	for(std::string dir; std::getline(spath, dir, '/'); ) {
		dirs.push_back(dir);
	}
	int dsize = dirs.size();
	if( ! isdir ) dsize--;
	std::string pathcur;
	for( int idir=0; idir<dsize; idir++ ) {
		pathcur += dirs[idir];
		if( MKDir( pathcur.c_str() ) )
			WarningEA::Other(FuncName, "Making directory: " + pathcur );
		pathcur += "/";
	}
}
FileCollector *MultiThreadedFileCollector::getCollectorOfCurrentThread() {
	thread::id this_thread_id = std::this_thread::get_id();
	typename map<thread::id, FileCollector*>::iterator it =
					collectors->find(this_thread_id);
	FileCollector *result;
	if (it == collectors->end())
	{	// not found, create the collector

		std::ostringstream spath(_prefix);
		spath << this_thread_id << ".dat";
		string path = spath.str();
		result = new FileCollector(path);
		(*collectors)[this_thread_id] = result;
	}
	else
	{	// found
		result = it->second;
	}

	return result;
}
Example #7
0
BlocksInfo blocks(const std::vector<Path2d>& boundaries, double side, bool oddeven)
{
    std::vector<Path2d> paths;
    std::vector<Path2d> grid;
    int h, w;
    int x0, y0, x1, y1;
    P2d p0, p1, po, pa, pb;

    for (int j=0,m=boundaries.size(); j<m; j++)
    {
        Path2d path = boundaries[j] / side;
        path.boundingBox(p0, p1, j!=0);
        paths.push_back(path);
    }

    x0 = int(floor(p0.x - side));
    y0 = int(floor(p0.y - side));
    x1 = int(ceil(p1.x + side));
    y1 = int(ceil(p1.y + side));

    po.x = x0;
    po.y = y0;
    for (int j=0,m=paths.size(); j<m; j++)
    {
        paths[j] -= po; /* align to image origin */
    }

    w = x1 - x0;
    h = y1 - y0;
    Image<int> image(w, h);
    image.fastBox(0, 0, w, h, 0); /* zero fill */

    if (oddeven) {
        polyFill(image, 1, paths);
        polyDraw(image, 1, paths);
    } else {
        /* vogliamo solo marcare le aree coperte dai perimetri esterni
         * senza considerare eventuali fori */
        std::vector<Path2d> spath(1);
        for (int j=0,m=paths.size(); j<m; j++)
        {
            spath[0] = paths[j];
            polyFill(image, 1, spath);
            polyDraw(image, 1, spath);
        }
    }

    paths.clear();

    int num=0;
    for(int x=-1; x<w; ++x) {
        for (int y=-1; y<h; ++y) {
            if (image.pixel(x, y, 0) != 0)
            {
                std::vector<P2d> points;
                pa.x = (x0 + x) * side;
                pa.y = (y0 + y) * side;
                pb.x = pa.x;
                pb.y = pa.y + side;
                points.push_back(pa);
                points.push_back(pb);
                pa.x = pb.x + side;
                pa.y = pb.y;
                points.push_back(pa);
                pb.x = pa.x;
                pb.y = pa.y - side;
                points.push_back(pb);
                pa.x = pb.x - side;
                pa.y = pb.y;
                points.push_back(pa);
                Path2d block(points);
                grid.push_back(block);
                num++;
            }
            /* due pixel accanto diversi*/
            if (image.pixel(x, y, 0) != image.pixel(x+1, y, 0)) {
                std::vector<P2d> points;
                pa.x = (x0 + x + 1) * side;
                pa.y = (y0 + y) * side;
                pb.x = pa.x;
                pb.y = pa.y + side;
                points.push_back(pa);
                points.push_back(pb);
                Path2d block(points);
                paths.push_back(block);
                /* due pixel uno sopra l'altro diversi*/
            }
            if (image.pixel(x, y, 0) != image.pixel(x, y+1, 0)) {
                std::vector<P2d> points;
                pa.x = (x0 + x) * side;
                pa.y = (y0 + y + 1) * side;
                pb.x = pa.x + side;
                pb.y = pa.y;
                points.push_back(pa);
                points.push_back(pb);
                Path2d block(points);
                paths.push_back(block);
            }
        }
    }
    BlocksInfo iblocks(num, paths, grid);
    return iblocks;
}
Example #8
0
File: kb.cpp Project: lockcda/ckb
Kb::Kb(QObject *parent, const QString& path) :
    QThread(parent), devpath(path), cmdpath(path + "/cmd"),
    features("N/A"), firmware("N/A"), pollrate("N/A"),
    _currentProfile(0), _currentMode(0), _model(KeyMap::NO_MODEL),
    _hwProfile(0), prevProfile(0), prevMode(0),
    cmd(cmdpath), notifyNumber(1), _needsSave(false)
{
    memset(hwLoading, 0, sizeof(hwLoading));
    // Get the features, model, serial number, FW version (if available), and poll rate (if available) from /dev nodes
    QFile ftpath(path + "/features"), mpath(path + "/model"), spath(path + "/serial"), fwpath(path + "/fwversion"), ppath(path + "/pollrate");
    if(ftpath.open(QIODevice::ReadOnly)){
        features = ftpath.read(1000);
        features = features.trimmed();
        ftpath.close();
        // Read model from features (first word: vendor, second word: product)
        QStringList list = features.split(" ");
        if(list.length() < 2)
            return;
        _model = KeyMap::getModel(list[1]);
        if(_model == KeyMap::NO_MODEL)
            return;
    } else
        // Bail if features aren't readable
        return;
    if(mpath.open(QIODevice::ReadOnly)){
        usbModel = mpath.read(100);
        usbModel = usbModel.remove("Corsair").remove("Gaming").remove("Keyboard").remove("Mouse").remove("Bootloader").trimmed();
        mpath.close();
    }
    if(usbModel == "")
        usbModel = "Keyboard";
    if(spath.open(QIODevice::ReadOnly)){
        usbSerial = spath.read(100);
        usbSerial = usbSerial.trimmed().toUpper();
        spath.close();
    }
    if(usbSerial == "")
        usbSerial = "Unknown-" + usbModel;
    if(features.contains("fwversion") && fwpath.open(QIODevice::ReadOnly)){
        firmware = fwpath.read(100);
        firmware = QString::number(firmware.trimmed().toInt() / 100., 'f', 2);
        fwpath.close();
    }
    if(features.contains("pollrate") && ppath.open(QIODevice::ReadOnly)){
        pollrate = ppath.read(100);
        pollrate = pollrate.trimmed();
        ppath.close();
    }

    hwModeCount = (_model == KeyMap::K95) ? 3 : 1;
    // Open cmd in non-blocking mode so that it doesn't lock up if nothing is reading
    // (e.g. if the daemon crashed and didn't clean up the node)
    int fd = open(cmdpath.toLatin1().constData(), O_WRONLY | O_NONBLOCK);
    if(!cmd.open(fd, QIODevice::WriteOnly, QFileDevice::AutoCloseHandle))
        return;

    // Find an available notification node (if none is found, take notify1)
    for(int i = 1; i < 10; i++){
        QString notify = QString(path + "/notify%1").arg(i);
        if(!QFile::exists(notify)){
            notifyNumber = i;
            notifyPath = notify;
            break;
        }
    }
    cmd.write(QString("notifyon %1\n").arg(notifyNumber).toLatin1());
    cmd.flush();
    // Activate device, apply settings, and ask for hardware profile
    cmd.write(QString("fps %1\n").arg(_frameRate).toLatin1());
    cmd.write(QString("dither %1\n").arg(static_cast<int>(_dither)).toLatin1());
#ifdef Q_OS_MACX
    // Write ANSI/ISO flag to daemon (OSX only)
    cmd.write("layout ");
    cmd.write(KeyMap::isISO(_layout) ? "iso" : "ansi");
#endif
    cmd.write(QString("\nactive\n@%1 get :hwprofileid").arg(notifyNumber).toLatin1());
    hwLoading[0] = true;
    for(int i = 0; i < hwModeCount; i++){
        cmd.write(QString(" mode %1 get :hwid").arg(i + 1).toLatin1());
        hwLoading[i + 1] = true;
    }
    cmd.write("\n");
    cmd.flush();

    emit infoUpdated();
    activeDevices.insert(this);

    // Start a separate thread to read from the notification node
    start();
}
Example #9
0
string PathToExe()
{
    int bufsize = 255;
    char *path = NULL;
    bool done = false;

// Pre-loop initialization.
#ifdef WIN32
    // Will contain exe path
    HMODULE hModule = GetModuleHandle(NULL);
    if (hModule != NULL)
    {
#endif

    while( !done )
    {
        path = (char*) realloc( path, bufsize * sizeof(char));

#ifdef WIN32
        DWORD size = GetModuleFileName(hModule, path, bufsize);
        if( size < bufsize )
        {
            char *cpath = (char*) malloc( 2 * bufsize * sizeof(char) );
            PathCanonicalize( cpath, path );
            if ( cpath )
            {
                free( path );
                path = cpath;
            }
            PathRemoveFileSpec( path );
            done = true;
        }
#else

#ifdef __APPLE__
        uint32_t size = bufsize;
        if (_NSGetExecutablePath(path, &size) == 0)
        {
            done = true;
        }
#else
        ssize_t size = readlink("/proc/self/exe", path, bufsize);
        if ( size < bufsize - 1 )
        {
            path[size] = '\0';
            done = true;
        }
#endif
        if ( done )
        {
            char* cpath = NULL;
            cpath = realpath( path, NULL );
            if ( cpath )
            {
                free( path );
                path = cpath;
            }

            char *ppath = (char*) malloc( 2 * bufsize * sizeof(char) );
            strcpy( ppath, path );
            ppath = dirname( ppath );
            if ( ppath )
            {
                free( path );
                path = ppath;
            }
        }
#endif

        bufsize *= 2;
    }  // while( !done )

// Handle pre-loop initialization failure.
#ifdef WIN32
    }
    else
    {
        path = (char*) realloc( path, bufsize * sizeof(char));
        path[0] = '\0';
    }
#endif

    string spath( path );

    free( path );

    return spath;
}