Example #1
0
int execute_file(const boost::filesystem::wpath & path)
{
#if BOOST_WINDOWS
    STARTUPINFOW si;
    PROCESS_INFORMATION pi;
    memset(&si, 0, sizeof(si));
    memset(&pi, 0, sizeof(pi));
    si.cb = sizeof(si);
    boost::filesystem::wpath parent = path;
    parent.remove_filename();
    if(CreateProcessW(NULL, const_cast<wchar_t*>(wfname(path).c_str()), NULL, NULL, true, CREATE_NO_WINDOW, NULL, wfname(parent).c_str(), &si, &pi))
    {
        CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
        return pi.dwProcessId;
    } else
        return -1;
#else
    std::string fname = mstd::utf8fname(path);
    int result = vfork();
    if(!result)
    {
        execl(fname.c_str(), fname.c_str(), NULL);
        _exit(0);
    }
    return result;
#endif
}
Example #2
0
inline std::string apifname(const boost::filesystem::wpath & path)
{
#if BOOST_WINDOWS
	return narrow(wfname(path));
#else
	return utf8fname(path);
#endif
}
Example #3
0
int execute_file(const boost::filesystem::wpath & path, const std::vector<std::wstring> & arguments, void ** handle)
{    
#if !BOOST_WINDOWS
    std::string fname = mstd::utf8fname(path);
    std::vector<std::string> args;
    args.reserve(arguments.size());
    std::vector<char*> argv;
    argv.reserve(arguments.size() + 2);
    argv.push_back(const_cast<char*>(fname.c_str()));
    for(std::vector<std::wstring>::const_iterator i = arguments.begin(), end = arguments.end(); i != end; ++i)
    {
        args.push_back(utf8(*i));
        argv.push_back(const_cast<char*>(args.back().c_str()));
    }
    argv.push_back(0);
    int result = vfork();
    if(!result)
    {
        execv(fname.c_str(), &argv[0]);
        _exit(0);
    }
    return result;
#else
    STARTUPINFOW si;
    PROCESS_INFORMATION pi;
    HANDLE ipipe = 0, opipe = 0;
    CreatePipe(&ipipe, &opipe, 0, 0);
    memset(&si, 0, sizeof(si));
    si.hStdInput = ipipe;
    si.hStdOutput = si.hStdError = opipe;
    memset(&pi, 0, sizeof(pi));
    si.cb = sizeof(si);
    boost::filesystem::wpath parent = path;
    parent.remove_filename();
    std::wstring command = escape(wfname(path));
    for(std::vector<std::wstring>::const_iterator i = arguments.begin(), end = arguments.end(); i != end; ++i)
    {
        command += L' ';
        command += escape(*i);
    }

    if(CreateProcessW(NULL, const_cast<wchar_t*>(command.c_str()), NULL, NULL, true, 0, NULL, wfname(parent).c_str(), &si, &pi))
    {
        if(handle)
            *handle = pi.hProcess;
        else
            CloseHandle(pi.hProcess);
        CloseHandle(pi.hThread);
        return pi.dwProcessId;
    } else {
        if(handle)
            *handle = INVALID_HANDLE_VALUE;
        return -1;
    }
#endif
}
Example #4
0
void execute_file(const boost::filesystem::wpath & path)
{
#if BOOST_WINDOWS
    STARTUPINFOW si;
    PROCESS_INFORMATION pi;
    memset(&si, 0, sizeof(si));
    memset(&pi, 0, sizeof(pi));
    si.cb = sizeof(si);
    CreateProcessW(NULL, const_cast<wchar_t*>(wfname(path).c_str()), NULL, NULL, true, 0, NULL, NULL, &si, &pi);
#else
    std::string fname = apifname(path).c_str();
    if(!vfork())
    {
        execl(fname.c_str(), NULL, NULL);
        _exit(0);
    }
#endif
}
bool WorkspaceLoader::Save(const wxString& title, const wxString& filename)
{
    const char* ROOT_TAG = "CodeBlocks_workspace_file";

    TiXmlDocument doc;
    doc.SetCondenseWhiteSpace(false);
    doc.InsertEndChild(TiXmlDeclaration("1.0", "UTF-8", "yes"));
    TiXmlElement* rootnode = static_cast<TiXmlElement*>(doc.InsertEndChild(TiXmlElement(ROOT_TAG)));
    if (!rootnode)
        return false;

    TiXmlElement* wksp = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("Workspace")));
    wksp->SetAttribute("title", cbU2C(title));

    ProjectsArray* arr = Manager::Get()->GetProjectManager()->GetProjects();
    for (unsigned int i = 0; i < arr->GetCount(); ++i)
    {
        cbProject* prj = arr->Item(i);

        wxFileName wfname(filename);
        wxFileName fname(prj->GetFilename());
        fname.MakeRelativeTo(wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));

        TiXmlElement* node = static_cast<TiXmlElement*>(wksp->InsertEndChild(TiXmlElement("Project")));
        node->SetAttribute("filename", cbU2C( ExportFilename(fname) ) );
        if (prj == Manager::Get()->GetProjectManager()->GetActiveProject())
            node->SetAttribute("active", 1);

        const ProjectsArray* deps = Manager::Get()->GetProjectManager()->GetDependenciesForProject(prj);
        if (deps && deps->GetCount())
        {
            for (size_t i = 0; i < deps->GetCount(); ++i)
            {
                prj = deps->Item(i);
                fname.Assign(prj->GetFilename());
                fname.MakeRelativeTo(wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
                TiXmlElement* dnode = static_cast<TiXmlElement*>(node->InsertEndChild(TiXmlElement("Depends")));
                dnode->SetAttribute("filename", cbU2C( ExportFilename(fname) ) );
            }
        }
    }
    return cbSaveTinyXMLDocument(&doc, filename);
}
Example #6
0
void emit_events(WatchData &watch){
	PFILE_NOTIFY_INFORMATION info;
	size_t offset = 0;
	do {
		info = reinterpret_cast<PFILE_NOTIFY_INFORMATION>(&watch.info_buf[0] + offset);
		offset += info->NextEntryOffset;
		//FileNameLength is size in bytes of the 16-bit Unicode string so, compute
		//the max number of chars that it could contain
		//This is done to put the null terminator on the end of the string since
		//Win32 doesn't null-terminate
		int n_chars = info->FileNameLength / 2;
		std::vector<wchar_t> wfname(n_chars + 1);
		std::memcpy(&wfname[0], info->FileName, info->FileNameLength);
		char fname[MAX_PATH + 1] = { 0 };
		std::wcstombs(fname, &wfname[0], MAX_PATH);
		//Since FILE_NOTIFY_CHANGE_FILE_NAME gives all create/delete/rename events it's possible that
		//we only want create but have gotten one of the other two, so make sure we actually want this
		uint32_t action = remap_file_action(info->Action);
		if (action & watch.filter){
			watch.callback(EventData{watch.dir_name, fname, watch.filter, action});
		}
	}
	while (info->NextEntryOffset != 0);
}
bool WorkspaceLoader::Open(const wxString& filename, wxString& Title)
{
    TiXmlDocument doc;
    if (!TinyXML::LoadDocument(filename, &doc))
        return false;

//    ProjectManager* pMan = Manager::Get()->GetProjectManager();
//    LogManager* pMsg = Manager::Get()->GetLogManager();

    if (!GetpMan() || !GetpMsg())
        return false;

    // BUG: Race condition. to be fixed by Rick.
    // If I click close AFTER pMan and pMsg are calculated,
    // I get a segfault.
    // I modified classes projectmanager and logmanager,
    // so that when self==NULL, they do nothing
    // (constructors, destructors and static functions excempted from this)
    // This way, we'll use the *manager::Get() functions to check for nulls.

    TiXmlElement* root = doc.FirstChildElement("CodeBlocks_workspace_file");
    if (!root)
    {
        // old tag
        root = doc.FirstChildElement("Code::Blocks_workspace_file");
        if (!root)
        {
            GetpMsg()->DebugLog(_T("Not a valid Code::Blocks workspace file..."));
            return false;
        }
    }
    TiXmlElement* wksp = root->FirstChildElement("Workspace");
    if (!wksp)
    {
        GetpMsg()->DebugLog(_T("No 'Workspace' element in file..."));
        return false;
    }

    Title = cbC2U(wksp->Attribute("title")); // Conversion to unicode is automatic (see wxString::operator= )

    TiXmlElement* proj = wksp->FirstChildElement("Project");
    if (!proj)
    {
        GetpMsg()->DebugLog(_T("Workspace file contains no projects..."));
        return false;
    }

    // first loop to load projects
    while (proj)
    {
        if(Manager::isappShuttingDown() || !GetpMan() || !GetpMsg())
            return false;
        wxString projectFilename = UnixFilename(cbC2U(proj->Attribute("filename")));
        if (projectFilename.IsEmpty())
        {
            GetpMsg()->DebugLog(_T("'Project' node exists, but no filename?!?"));
        }
        else
        {
            wxFileName fname(projectFilename);
            wxFileName wfname(filename);
            fname.MakeAbsolute(wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
            int active = 0;
            int ret = proj->QueryIntAttribute("active", &active);
            switch (ret)
            {
                case TIXML_SUCCESS:
                    if (active == 1)
					{
						cbProject* pProject = GetpMan()->LoadProject(fname.GetFullPath(), true); // activate it
						if(!pProject)
						{
							cbMessageBox(_("Unable to open ") + projectFilename,
							 _("Opening WorkSpace") + filename, wxICON_WARNING);
						}
					}
                    break;
                case TIXML_WRONG_TYPE:
                    GetpMsg()->DebugLog(F(_T("Error %s: %s"), doc.Value(), doc.ErrorDesc()));
                    GetpMsg()->DebugLog(_T("Wrong attribute type (expected 'int')"));
                    break;
                default:
					cbProject* pProject = GetpMan()->LoadProject(fname.GetFullPath(), false); // don't activate it
					if(!pProject)
					{
						cbMessageBox(_("Unable to open ") + projectFilename,
						 _("Opening WorkSpace") + filename, wxICON_WARNING);
					}
                    break;
            }
        }
        proj = proj->NextSiblingElement("Project");
    }

    // second loop to setup dependencies
    proj = wksp->FirstChildElement("Project");
    while (proj)
    {
        cbProject* thisprj = 0;
        wxString projectFilename = UnixFilename(cbC2U(proj->Attribute("filename")));
        if (projectFilename.IsEmpty())
        {
            GetpMsg()->DebugLog(_T("'Project' node exists, but no filename?!?"));
            thisprj = 0;
        }
        else
        {
            wxFileName fname(projectFilename);
            wxFileName wfname(filename);
            fname.MakeAbsolute(wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
            thisprj = Manager::Get()->GetProjectManager()->IsOpen(fname.GetFullPath());
        }

        if (thisprj)
        {
            TiXmlElement* dep = proj->FirstChildElement("Depends");
            while (dep)
            {
                wxFileName fname(UnixFilename(cbC2U(dep->Attribute("filename"))));
                wxFileName wfname(filename);
                fname.MakeAbsolute(wfname.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR));
                cbProject* depprj = Manager::Get()->GetProjectManager()->IsOpen(fname.GetFullPath());
                if (depprj)
                    Manager::Get()->GetProjectManager()->AddProjectDependency(thisprj, depprj);
                dep = dep->NextSiblingElement("Depends");
            }
        }
        proj = proj->NextSiblingElement("Project");
    }

    return true;
}
HRESULT Mesh::Create(ID3D11Device * pDevice, const char * path, const char * name, bool sdkmesh)
{
    m_isSdkMesh = sdkmesh;

    if (sdkmesh)
    {
        char filename[256];
        sprintf(filename, "%s%s", path, name);
        std::string fname(filename);
        std::wstring wfname(fname.begin(), fname.end());

        return m_sdkMesh.Create(pDevice, wfname.c_str(), false);
    }
#ifdef AMD_SDK_MINIMAL
    else
    {
        // the minimal-dependencies version of AMD_SDK
        // only supports sdkmesh
        return E_FAIL;
    }
#else
    HRESULT             hr = S_OK;
    Assimp::Importer    importer;
    int                 num_vertices = 0;
    int                 num_faces = 0;

    std::string filename = std::string(path) + std::string(name);

    aiScene* scene = (aiScene*)importer.ReadFile(filename.c_str(), 0);

    if (!scene) { return E_FAIL; }

    _id = crcFast((const unsigned char *)filename.c_str(), (int)filename.length());

    if (scene->HasMeshes() && scene->mNumMeshes > 0)
    {
        for (int i = 0; i < (int)scene->mNumMeshes; i++)
        {
            num_vertices += scene->mMeshes[i]->mNumVertices;
            num_faces += scene->mMeshes[i]->mNumFaces;
        }

        if (num_vertices == 0 || num_faces == 0)  { return S_OK; }

        int current_vertex = 0;
        int current_face = 0;

        _material_group.resize(scene->mNumMeshes);
        _vertex.resize(num_vertices);
        _index.resize(num_faces * 3);

        ID3D11DeviceContext * pContext = NULL;
        pDevice->GetImmediateContext(&pContext);

        for (unsigned int i = 0; i < scene->mNumMeshes; i++)
        {
            ID3D11Texture2D * t2d = NULL;
            ID3D11ShaderResourceView * srv = NULL;

            aiMesh * mesh = scene->mMeshes[i];
            aiMaterial * material = scene->mMaterials[mesh->mMaterialIndex];
            aiString c_texture_filename;
            material->Get(AI_MATKEY_TEXTURE_DIFFUSE(0), c_texture_filename);

            std::string tex_filename = std::string(path) + std::string(c_texture_filename.C_Str());
            {
                WCHAR wc_texture_filename[1024];
                mbstowcs(wc_texture_filename, tex_filename.c_str(), tex_filename.length() + 1);

                unsigned int bind_flags = D3D11_BIND_SHADER_RESOURCE;
                hr = DirectX::CreateDDSTextureFromFileEx(pDevice, wc_texture_filename, 0, D3D11_USAGE_DEFAULT, bind_flags, 0, 0, true, (ID3D11Resource**)&t2d, &srv);
            }

            _material_group[i]._texture_index = (int)_t2d.size();
            _t2d.push_back(t2d);
            _srv.push_back(srv);

            _material_group[i]._first_index = current_face;
            _material_group[i]._index_count = mesh->mNumFaces * 3;

            aiVector3D * position = mesh->HasPositions() ? mesh->mVertices : NULL;
            aiVector3D * normal = mesh->HasNormals() ? mesh->mNormals : NULL;
            aiVector3D * uv = mesh->HasTextureCoords(0) ? mesh->mTextureCoords[0] : NULL;

            for (unsigned int j = 0; j < mesh->mNumVertices; j++)
            {
                if (position != NULL)
                {
                    memcpy( &_vertex[current_vertex + j].position, &position[j], sizeof( float ) * 3 );
                }

                if (normal != NULL)
                {
                    memcpy( &_vertex[current_vertex + j].normal, &normal[j], sizeof( float ) * 3 );
                }

                if (uv != NULL)
                {
                    memcpy( &_vertex[current_vertex + j].uv, &uv[j], sizeof( float ) * 2 );
                }
            }

            if (mesh->HasFaces())
            {
                aiFace * f = mesh->mFaces;
                for (unsigned int j = 0; j < mesh->mNumFaces; j++)
                {
                    _index[current_face + j * 3 + 0] = current_vertex + f[j].mIndices[0];
                    _index[current_face + j * 3 + 1] = current_vertex + f[j].mIndices[1];
                    _index[current_face + j * 3 + 2] = current_vertex + f[j].mIndices[2];
                }
            }

            current_face += mesh->mNumFaces * 3;
            current_vertex += mesh->mNumVertices;
        }

        AMD_SAFE_RELEASE(pContext);

        CD3D11_BUFFER_DESC vertexDesc, indexDesc;
        vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER | D3D11_BIND_SHADER_RESOURCE;
        vertexDesc.ByteWidth = sizeof(Vertex) * num_vertices;
        vertexDesc.CPUAccessFlags = 0;
        vertexDesc.MiscFlags = 0;
        vertexDesc.StructureByteStride = 0;
        vertexDesc.Usage = D3D11_USAGE_IMMUTABLE;
        indexDesc.BindFlags = D3D11_BIND_INDEX_BUFFER;
        indexDesc.ByteWidth = sizeof(int) * num_faces * 3;
        indexDesc.CPUAccessFlags = 0;
        indexDesc.MiscFlags = 0;
        indexDesc.StructureByteStride = 0;
        indexDesc.Usage = D3D11_USAGE_IMMUTABLE;

        D3D11_SUBRESOURCE_DATA vertexData, indexData;
        memset(&vertexData, 0, sizeof(vertexData));
        memset(&indexData, 0, sizeof(indexData));

        vertexData.pSysMem = &_vertex[0];
        indexData.pSysMem = &_index[0];

        hr = pDevice->CreateBuffer(&vertexDesc, &vertexData, &_b1d_vertex);
        hr = pDevice->CreateBuffer(&indexDesc, &indexData, &_b1d_index);
    }

    return hr;
#endif
}