Exemplo n.º 1
0
/* Here we use the absolute path name as the lock name.  See fd.c 
 * for how the name is created (GP_TEMP_FILE_DIR and make_database_relative).
 */
static void
sisc_lockname(char *p, int size, int share_id, const char* name)
{
	char		filename[MAXPGPATH];
	char	   *path;

	snprintf(filename, sizeof(filename),
			 "gpcdb2.sisc_%d_%d_%d_%d_%s",
			 GpIdentity.segindex, gp_session_id, gp_command_count, share_id, name);

	path = GetTempFilePath(filename, true);
	if (strlen(path) >= size)
		elog(ERROR, "path to temporary file too long: %s", path);
	strcpy(p, path);
}
Exemplo n.º 2
0
void ArrayWriterToTmpFile::Writer(ImageArray* img)
{
    CString tmpfilename = GetTempFilePath(L"Image2Code");

    CStdioFile tmp;
    if (tmp.Open(tmpfilename,CFile::modeCreate|CFile::modeWrite|CFile::typeText)) {

        IWriter(&tmp,img);

        tmp.Close();

        STARTUPINFO si;
        PROCESS_INFORMATION pi;

        ZeroMemory( &si, sizeof(si) );
        si.cb = sizeof(si);
        ZeroMemory( &pi, sizeof(pi) );

        CString command(L"notepad");
        command += L" ";
        command += tmpfilename;

        BOOL run = CreateProcess( NULL,
            T2W(command.GetBuffer()),    // Command line
            NULL,           // Process handle not inheritable
            NULL,           // Thread handle not inheritable
            FALSE,          // Set handle inheritance to FALSE
            0,              // No creation flags
            NULL,           // Use parent's environment block
            NULL,           // Use parent's starting directory 
            &si,            // Pointer to STARTUPINFO structure
            &pi );          // Pointer to PROCESS_INFORMATION structure

        if (run) {
            CloseHandle(pi.hProcess);
            CloseHandle(pi.hThread);
        }
        else {
            AfxMessageBox(IDS_IMAGE_NONOTEPAD, MB_OK|MB_ICONSTOP);
        }

    }
    else {
        AfxMessageBox(IDS_IMAGE_TMPFILEFAIL, MB_OK|MB_ICONSTOP);
    }

}
Exemplo n.º 3
0
void
SourceFileRez::RemoveObjects(BuildInfo &info)
{
	if (BString(GetPath().GetExtension()).ICompare("r") != 0)
		return;
	
	DPath path(GetTempFilePath(info));
	
	BString base = path.GetFolder();
	base << "/" << path.GetBaseName() << ".txt";
	BEntry(base.String()).Remove();

	base = path.GetFolder();
	base << "/" << path.GetBaseName();
	base.RemoveLast(".r");
	base << ".rsrc";
	BEntry(base.String()).Remove();
}
Exemplo n.º 4
0
void
SourceFileRez::Compile(BuildInfo &info, const char *options)
{
	BString abspath = GetPath().GetFullPath();
	if (abspath[0] != '/')
	{
		abspath.Prepend("/");
		abspath.Prepend(info.projectFolder.GetFullPath());
	}
	
	if (BString(GetPath().GetExtension()).ICompare("r") != 0)
		return;
	
	BString pipestr = "rez -t ";
	
	for (int32 i = 0; i < info.includeList.CountItems(); i++)
		pipestr << "'-I" << info.includeList.ItemAt(i)->Absolute() << "' ";
	
	pipestr << "-o '" << GetResourcePath(info).GetFullPath()
			<< "' '" << GetTempFilePath(info).GetFullPath() << "' 2>&1";
	
	FILE *fd = popen(pipestr.String(),"r");
	if (!fd)
		return;
	
	char buffer[1024];
	BString errmsg;
	while (fgets(buffer,1024,fd))
		errmsg += buffer;
	pclose(fd);
	
	STRACE(1,("Compiling %s\nCommand:%s\nOutput:%s\n",
			abspath.String(),pipestr.String(),errmsg.String()));
	
	ParseRezErrors(errmsg.String(),info.errorList);
	
	if (info.errorList.msglist.CountItems() > 0)
	{
		BEntry entry(GetResourcePath(info).GetFullPath());
		entry.Remove();
	}
}
Exemplo n.º 5
0
bool InstallDriver(const TCHAR* drv_name)
{
        // Extract driver from resource and write it to disk
        DWORD drv_size           = 0;
        TCHAR drv_path[MAX_PATH] = {};
        void* drv_data           = ExtractDriver(&drv_size);

        if (!drv_data)
                return false;

        GetTempFilePath(drv_path, _countof(drv_path), _T("drv"));

        FILE* f = _tfopen(drv_path, _T("wb"));

        fwrite(drv_data, drv_size, 1, f);
        fclose(f);
        
        // Open SC manager and load the driver to kernel
        bool ret             = false;
        SC_HANDLE sc_manager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
        SC_HANDLE drv        = NULL;

        if (!sc_manager) {
                Error("Create SC manager fail!");
                goto error_out;
        }
        
        drv = CreateService(sc_manager,
                            drv_name,
                            drv_name,
                            SERVICE_ALL_ACCESS,
                            SERVICE_KERNEL_DRIVER,
                            SERVICE_DEMAND_START,
                            SERVICE_ERROR_IGNORE,
                            drv_path,
                            NULL,
                            NULL,
                            NULL,
                            NULL,
                            NULL);
        if (!drv) {
                DWORD err = GetLastError();

                if (ERROR_IO_PENDING != err && ERROR_SERVICE_EXISTS != err) {
                        Error("Create driver service fail!");
                        goto error_out;
                }

                // The driver service already exist, we can just open it
                drv = OpenService(sc_manager, drv_name, SERVICE_ALL_ACCESS);

                if (!drv) {
                        Error("Open driver service fail!");
                        goto error_out;
                }
        }
        
        // This will invoke the DriverEntry routine
        if (!StartService(drv, NULL, NULL)) {
                DWORD err = GetLastError();

                if (ERROR_IO_PENDING == err) {
                        puts("start driver serivce fail, ERROR_IO_PENDING");
                        goto error_out;
                }

                if (ERROR_SERVICE_ALREADY_RUNNING == err)
                        puts("service already running!");
        }
        
        ret = true;
error_out:
        remove(drv_path);

        if (drv)
                CloseServiceHandle(drv);

        if (sc_manager)
                CloseServiceHandle(sc_manager);

        return ret;
}
Exemplo n.º 6
0
RadioCL* PlaylistCL::Parse(QUrl pURL){

    RadioCL* newRadio=NULL;

    if (pURL.isLocalFile()){
        QString tFileName=pURL.path().mid(1,pURL.path().length()-1);
        QStringList tFileNameParts=tFileName.split(".");

        QFile drFile(tFileName);
        if (!drFile.open(QIODevice::ReadOnly)){
            qDebug()<<"Unable to open"<<drFile.fileName();
        }
        else{
            drFile.close();
            if ( tFileNameParts.last()=="pls" || tFileNameParts.last()=="m3u"){
                 qDebug()<<"Dropped content is acceptable";
                 if (tFileNameParts.last()=="pls"){
                    newRadio=ParsePls(tFileName);
                    newRadio->SetPlaylist(pURL.url());
                 }
                 if (tFileNameParts.last()=="m3u"){
                    newRadio=ParseM3U(tFileName);
                    newRadio->SetPlaylist(pURL.url());
                 }
            }
            else{
                 qDebug()<<"Parse works with pls and m3u only";
            }
        }
    }
    else{
        // remote url
        qDebug()<<"Getting playlist from "<<pURL.url();
        QNetworkAccessManager *manager = new QNetworkAccessManager(this);

        if (Proxy!=""){
            manager->setProxy(QNetworkProxy(QNetworkProxy::HttpProxy,Proxy,ProxyPort.toInt(),ProxyUser,ProxyPass));
        }


        QNetworkRequest req;
        req.setUrl(pURL);
        QNetworkReply *tRemotePlaylist=manager->get(req);


        QEventLoop loop;
        connect(manager, SIGNAL(finished(QNetworkReply*)), &loop, SLOT(quit()));
        QApplication::setOverrideCursor(Qt::WaitCursor);
        loop.exec();
        QApplication::restoreOverrideCursor();

        qDebug()<<"Got replay:"<<tRemotePlaylist->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
        if (tRemotePlaylist->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt()==0)
                return(NULL);

        QString tPlaylist=QString(tRemotePlaylist->readAll());
        qDebug()<<"Got playlist as:"<<tPlaylist;
        if (tPlaylist=="")
            return(NULL);
        //qDebug()<<"Headers are:"<<tRemotePlaylist->rawHeaderList();
        //qDebug()<<"Content-Disposition:"<<tRemotePlaylist->rawHeader("Content-Disposition");

        QFile tTempFile(GetTempFilePath());
        if (!tTempFile.open(QIODevice::WriteOnly | QIODevice::Truncate)){
            qDebug()<<"Unable to open"<<tTempFile.fileName();
        }
        int tFileNamePos=tPlaylist.indexOf("filename=",0,Qt::CaseInsensitive);
        int tFileNameEndPos=tPlaylist.indexOf("\n",tFileNamePos,Qt::CaseInsensitive);
        int tFileBeginningPos=tPlaylist.indexOf("\n\n",tFileNameEndPos);

        QString tFileBody;
        if (tFileNamePos!=-1){
            if (tFileNameEndPos!=-1 && tFileBeginningPos!=-1){
                QString tPlaylistName=tPlaylist.mid(tFileNamePos+9,tFileNameEndPos-9-tFileNamePos);
                qDebug()<<"Playlist filename="<<tPlaylistName;
                tFileBody=tPlaylist.right(tPlaylist.length()-tFileBeginningPos-2);
            }
            else{
                qDebug()<<"Error in playlist";
            }
        }
        else{
            tFileBody=tPlaylist;
        }
        qDebug()<<"FileBody:"<<tFileBody;
        tTempFile.write(tFileBody.toLocal8Bit(),tFileBody.length());
        tTempFile.close();

        if (tFileBody.indexOf("[playlist]",Qt::CaseInsensitive)!=-1){
            newRadio=ParsePls(tTempFile.fileName());
        }
        else{
            newRadio=ParseM3U(tTempFile.fileName());
        }
        newRadio->SetPlaylist(pURL.url());
    }

    return(newRadio);
}