コード例 #1
0
/**
 * Copy the downloaded patch over the existing data folder.
 */
bool CopyPatch(
  const launcher::Settings &settings,
  const tFileMap &filesToPatch) {

  Trace("Copying patched files.");

  bool rVal = true;
  for (tFileMap::const_iterator file = filesToPatch.begin(); file != filesToPatch.end(); ++file) {
    vfs::Path patchSrc = GetOutputPath(file->second.get_filename());
    vfs::Path patchDst = GetPatchedPath(file->second.get_filename());
    if (!vfs::util::Copy(patchSrc, patchDst)) {
      Log(LL::Error) << "Unable to copy file: " << patchSrc.str() << " to " << patchDst.str() << std::endl;
      rVal = false;
      continue;
    }
  }

  if (!rVal) {
    return false;
  }

  Trace("Cleaning up download.");
  for (tFileMap::const_iterator file = filesToPatch.begin(); file != filesToPatch.end(); ++file) {
    vfs::Path patchSrc = GetOutputPath(file->second.get_filename());
    if (!vfs::util::Remove(patchSrc)) {
      Log(LL::Warning) << "Unable to remove file: " << patchSrc.str() << std::endl;
    }
  }

  return rVal;
}
コード例 #2
0
int CTestClientServer::RunAlgorithm()
{
  try
  {
    int response = ImportInputData();
    RETURN_ASSERT_IF(!PinUpCustomData(), aiUnexpected);
    RETURN_ASSERT_IF(response != aiOk, response);

    // Initialize client
    int port;
    CAutoIGClient client;
    if (IsDebugExport())
      client.SetDebugExportPath(GetOutputPath());
    gml::Ref<Dashboard::IProgressBar> progress(new CDummyProgressBar());
    client.SetProgressBar(*progress);
    client.SetProjectInfo(*GetProject());
    RETURN_ASSERT_IF(!client.InitClient(port), aiUnexpected);

    // Try to start server
    if(CAutoIGServer::StartServerProcess(
      port, GetConfigFilePath(), false))
    {
      return client.PerformAllocation();
    }
    else
      return aiUnexpected;

    return aiOk; 
  }
  catch (CMemoryException* )
  {
    return aiOutOfMemory;
  };
};
コード例 #3
0
/**
 * Checks if the file already exists
 */
bool CheckFileExists(
  const std::string &filename,
  const Signature crc) {

  Trace("Checking file exists: " << filename);
  const vfs::Path outputPath = GetOutputPath(filename);
  vfs::FileStats stats = vfs::Stat(outputPath);
  if (!stats.m_exists) {
    return false;
  }
  return CheckSignature(outputPath, crc);
}
コード例 #4
0
/**
 * Downloads a single file from the specified server.
 */
bool GetOneFile(
  const launcher::Settings &settings,
  const std::string &filename, const Signature crc) {

  Trace("Attempting to download " << filename);

  core::net::NetClient client(core::net::eConnectionMode::TCP_ASYNC);
  std::string hostName;
  for (auto server = settings.get_patch_server_begin(); server != settings.get_patch_server_end(); ++server) {
    client.start(settings.get_patch_server(0));
    if (client.valid()) {
      hostName = wrappers::net::http::Uri(server->get_dns_name()).getHost();
      break;
    }
  }

  if (!client.valid()) {
    Log(LL::Error) << "Unable to connect to any servers." << std::endl;
    return false;
  }

  wrappers::net::http::HttpHeader header = wrappers::net::http::HttpHeader::Builder()
      .setRequestType(wrappers::net::http::HttpHeader::eRequestType::HTTP_REQUEST_GET)
      .setRequestPath(std::string("/") + settings.get_server_patch_dir() + filename)
      .addHeader("host", hostName)
      .build();

  if (!header.valid()) {
    return false;
  }
  client.send(header.asBlob());

  const vfs::Path outputPath = GetOutputPath(filename);
  vfs::ofstream outfile(outputPath, std::ios::binary | std::ios::out);
  if (!outfile.is_open()) {
    Log(LL::Error) << "Unable to open file: " << outputPath.str() << std::endl;
    return false;
  }
  wrappers::net::http::HttpFileHandler fileHandler(outfile);
  while (client.valid() && !fileHandler.done()) {
    client.update(fileHandler);
    core::thread::thisthread::yield();
  }
  client.stop();
  outfile.flush();

  if (!fileHandler.success()) {
    return false;
  }

  return CheckSignature(outputPath, crc);
}
コード例 #5
0
/**
 * Attempt to get patches.
 */
bool GetPatches(const launcher::Settings &settings) {
  Trace("Getting patch list");
  if (!GetOneFile(settings, "files.pb", 0)) {
    Log(LL::Error) << "Unable to get file listing." << std::endl;
    return false;
  }

  launcher::FileList newFileList;
  if (!appshared::parseProtoFromFile(GetOutputPath("files.pb"), newFileList)) {
    Log(LL::Error) << "Unable to parse file listing from server" << std::endl;
    return false;
  }

  launcher::FileList oldFileList;
  if (!appshared::parseProtoFromFile(GetPatchedPath("files.pb"), oldFileList)) {
    oldFileList = launcher::FileList();
  }

  Trace("Getting patch");
  std::map< std::string, launcher::FileEntry > filesToPatch = GetDiff(oldFileList, newFileList);
  if (settings.get_use_torrent()) {
    // TODO(kulseran): implement torrent mode
  } else {
    if (!DownloadPatch(settings, filesToPatch)) {
      return false;
    }
  }

  Trace("Applying patch");
  if (!CopyPatch(settings, filesToPatch)) {
    return false;
  }
  if (!vfs::util::Copy(GetOutputPath("files.pb"), GetPatchedPath("files.pb"))) {
    return false;
  }

  Trace("Done");
  return true;
}
コード例 #6
0
ファイル: driver.cpp プロジェクト: it3ration/opcpp
time_t opDriver::GetGeneratedDialectTimestamp(const opParameters& p) {
    // find the maximum timestamp on the dialects (input dialects, since we
    // output every time)
    time_t maxtime = 0;

    for (int i = 0; i < p.Dialects.size(); i++) {
        opString filestring = GetOutputPath(p, p.Dialects[i].GetString());

        path filepath = (filestring + ".ooh").GetString();

        // doh file exists?
        if (exists(filepath)) {
            maxtime = max(last_write_time(filepath), maxtime);
        }
    }

    return maxtime;
}
コード例 #7
0
ファイル: driver.cpp プロジェクト: it3ration/opcpp
bool opDriver::CodeCurrent() {
    // foreach dialect we have...
    // and all dependencies, are we up to date?
    // are we up to date?
    opSet<path>::iterator it = OhFiles.begin();
    opSet<path>::iterator end = OhFiles.end();

    time_t opcpptime = opPlatform::GetOpCppTimeStamp();

    while (it != end) {
        const path& ohfilepath = *it;

        // get the output path
        opString filestring = GetOutputPath(opParameters::Get(), ohfilepath);

        path oohfilepath = (filestring + ".ooh").GetString();
        path ocppfilepath = (filestring + ".ocpp").GetString();

        if (!exists(oohfilepath)) return false;

        if (!exists(ocppfilepath)) return false;

        time_t ohtime = last_write_time(ohfilepath);
        time_t oohtime = last_write_time(oohfilepath);
        time_t ocpptime = last_write_time(ocppfilepath);

        if (ohtime > oohtime || ohtime > ocpptime || opcpptime > oohtime ||
            opcpptime > ocpptime)
            return false;

        // now check dependencies
        FileNode file;
        file.LoadDependencies(filestring + ".depend");

        if (file.IsDependencyNewer(oohtime)) return false;

        ++it;
    }

    return true;
}
コード例 #8
0
static void GenerateArchiveFromFile(const std::string &file, void (*ChangeStatusText)(std::string))
{
	BSPFile* bsp;
	std::vector<std::string> requiredFiles;
	MistakesClass mistakes;

	(*ChangeStatusText)("Checking file location...");

	BSPFilePath bspPath(file);
	if (!bspPath.IsOk())
	{
		mistakes.wrongFilePlacing = true;
		mistakes.displayMistakes();
		(*ChangeStatusText)("Waiting for user input...");
		return;
	}

	(*ChangeStatusText)("Reading file...");
	bsp = new BSPFile(bspPath.GetPath());
	if (!bsp->IsOk())
	{
		MessageBox(g_hWinMain, "Error while reading the map file.", "Error", MB_OK | MB_ICONERROR);
		(*ChangeStatusText)("Waiting for user input...");
		return;
	}

	(*ChangeStatusText)("Analyzing compilation...");
	mistakes.noVisingOrLighting = (!bsp->IsVised() || !bsp->IsLighted());

	(*ChangeStatusText)("Analyzing textures...");
	ConcatStringVectorsWithoutDuplicates(&requiredFiles, bsp->GetUsedTextures());

	(*ChangeStatusText)("Analyzing required files in entities...");
	ConcatStringVectorsWithoutDuplicates(&requiredFiles, bsp->RequiredFilesInEntities());
	//requiredfiles in worldspawn; model in func_* / model; sky texture
	delete bsp; //not required anymore

	(*ChangeStatusText)("Analyzing dependencies in required files...");
	AddDependencies(&requiredFiles, bspPath.GetPb2BasePath());
	//adds dependencies in the above, recursively, without a depth limit

	(*ChangeStatusText)("Comparing required files with default files...");
	RemoveDefaultFiles(&requiredFiles);

	(*ChangeStatusText)("Looking for r_script, mapinfo and mapshot...");
	std::string name = bspPath.GetFilename();

	std::string tmp = GetRealFilename(bspPath.GetPb2BasePath(), "pics/mapshots/beta/" + name.substr(0, name.length() - 4) + ".img");
	if (tmp.length() > 0)
		requiredFiles.push_back(tmp);

	tmp = "maps/mapinfo/" + name.substr(0, name.length() - 4) + ".txt";
	if (FileExists(bspPath.GetPb2BasePath() + tmp))
		requiredFiles.push_back(tmp);	

	tmp = "scripts/" + name.substr(0, name.length() - 4) + ".txt";
	if (FileExists(bspPath.GetPb2BasePath() + tmp))
		requiredFiles.push_back(tmp);	

	(*ChangeStatusText)("Generating real filenames...");
	ReplaceWithRealFilenames(&requiredFiles, &mistakes, bspPath.GetPb2BasePath());
	//replace generic extensiosn (.img and .mdl) with the real ones (and adds a .skp file for every .skm)

	(*ChangeStatusText)("Checking textures...");
	CheckTextures(&requiredFiles, &mistakes, bspPath.GetPb2BasePath());
	//power of two? Non-hr4 version linked?
	
	requiredFiles.insert(requiredFiles.end(), bspPath.GetNonBasePath());

	(*ChangeStatusText)("Creating the archive...");
	std::string out = GetOutputPath(bspPath.GetFilename());
	if (out.length() == 0)
	{
		(*ChangeStatusText)("Aborted...");
		return;
	}
	
	if (CreateZip(out, requiredFiles, bspPath.GetPb2BasePath()))
	{
		if (mistakes.isAnythingWrong())
		{
			mistakes.displayMistakes();
		}
		MessageBox(g_hWinMain, "The archive has been created.\n\n"
								"Credits to the developers of the zlib and minizip libraries for providing "
								"a free solution for creating zip files.",
								"Archive successfully created", MB_ICONINFORMATION | MB_OK);
	}
	else
	{
		MessageBox(g_hWinMain, "Fatal error: could not create the archive.", "Fatal Error", MB_ICONERROR | MB_OK);
	}
	
	(*ChangeStatusText)("Waiting for user input...");
}
コード例 #9
0
ファイル: driver.cpp プロジェクト: it3ration/opcpp
bool opDriver::CleanMode(const opParameters& p) {
    opSet<path> dohfiles = GetDialectFiles();
    opSet<path> ohfiles = GetFiles();

    if (p.Verbose) Log("Cleaning generated files...");

    /*=== remove .oh generated code ===*/

    opSet<path>::iterator ohend = ohfiles.end();

    for (opSet<path>::iterator it = ohfiles.begin(); it != ohend; ++it) {
        string filename = GetOutputPath(p, (*it));
        string oohfilename = filename + ".ooh";
        string ocppfilename = filename + ".ocpp";
        string dependfilename = filename + ".depend";

        path oohpath = oohfilename;
        path ocpppath = ocppfilename;
        path dependpath = dependfilename;

        if (exists(oohpath)) remove(oohpath);

        if (exists(ocpppath)) remove(ocpppath);

        if (exists(dependpath)) remove(dependpath);
    }

    /*=== remove .doh generated code ===*/

    opSet<path>::iterator dohend = dohfiles.end();

    for (opSet<path>::iterator it = dohfiles.begin(); it != dohend; ++it) {
        string filename = GetOutputPath(p, (*it));
        string oohfilename = filename + ".ooh";
        string ocppfilename = filename + ".ocpp";
        string dependfilename = filename + ".depend";

        path oohpath = oohfilename;
        path ocpppath = ocppfilename;
        path dependpath = dependfilename;

        if (exists(oohpath)) remove(oohpath);

        if (exists(ocpppath)) remove(ocpppath);

        if (exists(dependpath)) remove(dependpath);
    }

    /*=== remove .index files ===*/

    string oohindex = GetOutputPath(p, "Generated.oohindex");
    path oohindexpath = oohindex;

    if (exists(oohindexpath)) remove(oohindexpath);

    string ocppindex = GetOutputPath(p, "Generated.ocppindex");
    path ocppindexpath = ocppindex;

    if (exists(ocppindexpath)) remove(ocppindexpath);

    /*=== remove .target files ===*/

    int size = p.Depend.size();

    for (int i = 0; i < size; i++) {
        opString filestring = p.Depend[i];
        path filepath = filestring.GetString();
        opString targetfile = filepath.leaf().c_str();

        targetfile += ".target";

        path targetpath =
            p.GeneratedDirectory.GetString() / targetfile.GetString();

        if (exists(targetpath)) remove(targetpath);
    }

    return true;
}
コード例 #10
0
ファイル: driver.cpp プロジェクト: it3ration/opcpp
bool opDriver::DialectModeFile(const opParameters& p, const path& filename) {
    double totaltimestart = opTimer::GetTimeSeconds();

    opError::Clear();

    // output compiling -file- to std out
    if (!p.Silent) {
        Log(opString("Reading dialect ") + filename.string() + " ...");
    }

    // load the oh file, it will be tracked elsewhere
    DialectFileNode* filenode = FileNode::Load<DialectFileNode>(
        filename.string(), opScanner::SM_DialectMode);

    // filenode should be non-null even if there were errors
    assert(filenode);

    if (opError::HasErrors()) {
        if (p.PrintTree) filenode->PrintTree(filename.string());

        opError::Print();

        return false;
    }

    // check for file not found error
    // 	if (filenode->FileNotFoundError())
    // 	{
    // 		opError::Print();
    //
    // 		//this is ambiguous doh!
    // 		//TODO: fix this to be specific
    // 		Log(opString("Cannot open input file \"") + filename.string() +
    // "\"!"); 		return false;
    // 	}
    //
    // 	//check for scanner error
    // 	if(filenode->ScanError())
    // 	{
    // 		opError::Print();
    //
    // 		if (p.Verbose)
    // 		{
    // 			Log("Compilation failed!");
    // 			Log("");
    // 		}
    //
    // 		return false;
    // 	}
    //
    // 	//check for parser errors
    // 	if(filenode->AnyErrors())
    // 	{
    // 		//print the tree (failure)
    // 		if (p.PrintTree)
    // 			filenode->PrintTree(filename.string());
    //
    // 		opError::Print();
    //
    // 		if (p.Verbose)
    // 		{
    // 			Log("Compilation failed!");
    // 			Log("");
    // 		}
    //
    // 		return false;
    // 	}

    opString spath = GetOutputPath(p, filename);
    path oohpath = (spath + ".ooh").GetString();
    path ocpppath = (spath + ".ocpp").GetString();
    path outputpath = oohpath.branch_path();

    if (!exists(outputpath)) create_directories(outputpath);

    // handle dialect writing
    // we always want to read dialects though.
    bool bwrite = true;
    if (!p.Force) {
        // we want to rebuild upon upgrades / new builds
        if (exists(oohpath) && exists(filename)) {
            time_t oohtime = last_write_time(oohpath);
            time_t opcpptime = opPlatform::GetOpCppTimeStamp();
            time_t dohtime = GetDialectTimestamp(p);

            filenode->LoadDependencies(spath + ".depend");
            bool bNewDepend = filenode->IsDependencyNewer(oohtime);

            if (bNewDepend) {
                if (p.Verbose) {
                    Log("Included dialect newer than generated dialect file, "
                        "forcing recompile ...");
                    Log("");
                }
            } else if (oohtime < opcpptime) {
                if (p.Verbose) {
                    Log(opPlatform::GetOpCppExecutableName() +
                        " newer than generated dialect file, forcing recompile "
                        "...");
                    Log("");
                }
            } else if (oohtime <= dohtime) {
                if (p.Verbose) {
                    Log("Dialect newer than generated dialect file, forcing "
                        "recompile ...");
                    Log("");
                }
            } else if (oohtime > dohtime) {
                if (p.Verbose) Log(filename.string() + " is up to date");

                bwrite = false;
            }
        }
    }

    if (bwrite) {
        try {
            // Save dependencies file.
            opString dependpath = spath + ".depend";
            filenode->SaveDependencies(dependpath);

            // open the output files for the generated code...
            FileWriteStream hfile(oohpath.string());
            FileWriteStream sfile(ocpppath.string());

            if (hfile.is_open() && sfile.is_open()) {
                filenode->SetFiles(oohpath.string(), ocpppath.string());

                opDialectStream filestream(hfile, sfile);

                // add the pre-pend path (for relative #lines)
                filestream.SetDepths(oohpath.string());

                // files are open, now print to them
                filenode->PrintDialectNode(filestream);

                filestream.Output();
            } else {
                Log("Could not open output file(s)!");
                return false;
            }
        } catch (opException::opCPP_Exception&) {
        }

        // print xml!
        if (p.PrintXml) {
            try {
                path xmlpath = (spath + ".xml").GetString();

                // open the output files for the generated code...
                boost::filesystem::ofstream xfile(xmlpath);

                if (xfile.is_open()) {
                    opXmlStream filestream(xfile);

                    // files are open, now print to them
                    filenode->PrintXml(filestream);
                } else {
                    Log("Could not open output xml file!");
                    return false;
                }
            } catch (opException::opCPP_Exception&) {
                //??? ever
            }
        }
    }

    double totaltimeend = opTimer::GetTimeSeconds();
    double totaltimeMs = (totaltimeend - totaltimestart) * 1000.0;

    // print the tree (success)
    if (p.PrintTree) filenode->PrintTree(filename.string());

    // write the verbose compilation notice
    if (p.Verbose) {
        Log("");
        Log(opString("Dialect reading successful ... took ") + totaltimeMs +
            " ms (" + filenode->GetScanMs() + " scan ms, " +
            filenode->GetParseMs() + " parse ms)");
        Log("");
    }

    return true;
}
コード例 #11
0
ファイル: driver.cpp プロジェクト: it3ration/opcpp
// compiles a file in normal mode
bool opDriver::NormalModeFile(const opParameters& p, const path& filename) {
    double totaltimestart = opTimer::GetTimeSeconds();

    // build the output filename strings...
    // fix this for ../ case (convert to string and find & replace...)
    opString sfile = GetOutputPath(p, filename);

    path oohpath = (sfile + ".ooh").GetString();
    path ocpppath = (sfile + ".ocpp").GetString();

    path outputpath = oohpath.branch_path();

    if (!exists(outputpath)) create_directories(outputpath);

    // lets check the timestamp...
    if (!p.Force) {
        time_t ohtime = last_write_time(filename);

        // we want to rebuild upon upgrades / new builds
        time_t opcpptime = opPlatform::GetOpCppTimeStamp();

        if (exists(oohpath) && exists(ocpppath)) {
            time_t oohtime = last_write_time(oohpath);
            time_t ocpptime = last_write_time(ocpppath);

            time_t dohtime = GetGeneratedDialectTimestamp(p);

            FileNode tempfile;
            tempfile.LoadDependencies(sfile + ".depend");
            bool bNewDepend = tempfile.IsDependencyNewer(oohtime);

            if (bNewDepend) {
                if (p.Verbose) {
                    Log("Included file newer than generated file, forcing "
                        "recompile ...");
                    Log("");
                }
            }
            // up to date if ooh newer than oh, and ooh newer than opcpp build
            else if (oohtime < opcpptime || ocpptime < opcpptime) {
                if (p.Verbose) {
                    Log(opPlatform::GetOpCppExecutableName() +
                        " newer than generated file, forcing recompile ...");
                    Log("");
                }
            } else if (oohtime <= dohtime || ocpptime <= dohtime) {
                if (p.Verbose) {
                    Log("Dialect newer than generated file, forcing recompile "
                        "...");
                    Log("");
                }
            } else if (oohtime > ohtime && ocpptime > ohtime) {
                if (p.Verbose) Log(filename.string() + " is up to date");

                return true;
            }
        }
    }

    opError::Clear();

    // output compiling -file- to std out
    if (!p.Silent) {
        Log(opString("Compiling ") + filename.string() + " ...");
    }

    // load the oh file, it will be tracked elsewhere
    OPFileNode* filenode =
        FileNode::Load<OPFileNode>(filename.string(), opScanner::SM_NormalMode);

    // filenode should be non-null even if there were errors
    assert(filenode);

    if (opError::HasErrors()) {
        if (p.PrintTree) filenode->PrintTree(filename.string());

        opError::Print();
        return false;
    }

    // no errors, let's print the output files
    try {
        // Save dependencies file.
        opString dependpath = sfile + ".depend";
        filenode->SaveDependencies(dependpath);

        // open the output files for the generated code...
        FileWriteStream hfile(oohpath.string());
        FileWriteStream sfile(ocpppath.string());

        if (hfile.is_open() && sfile.is_open()) {
            filenode->SetFiles(oohpath.string(), ocpppath.string());

            opFileStream filestream(hfile, sfile);

            // add the pre-pend path (for relative #lines)
            filestream.SetDepths(oohpath.string());

            // files are open, now print to them
            filenode->PrintNode(filestream);

            filestream.Output();
        } else {
            Log("Could not open output file(s)!");
            return false;
        }
    } catch (opException::opCPP_Exception&) {
        //??? ever
    }

    // print xml!
    if (p.PrintXml) {
        try {
            path xmlpath = (sfile + ".xml").GetString();

            // open the output files for the generated code...
            boost::filesystem::ofstream xfile(xmlpath);

            if (xfile.is_open()) {
                opXmlStream filestream(xfile);

                // files are open, now print to them
                filenode->PrintXml(filestream);
            } else {
                Log("Could not open output xml file!");
                return false;
            }
        } catch (opException::opCPP_Exception&) {
            //??? ever
        }
    }

    // any errors left?
    // shouldn't be really
    opError::Print();

    double totaltimeend = opTimer::GetTimeSeconds();
    double totaltimeMs = (totaltimeend - totaltimestart) * 1000.0;

    // TODO: allow PrintTree to any stream
    //		and add support for PrintTree to file
    // print the AST to stdout
    if (p.PrintTree) filenode->PrintTree(filename.string());

    // write the verbose compilation notice
    if (p.Verbose) {
        Log("");
        Log(opString("Compilation successful ... took ") + totaltimeMs +
            " ms (" + filenode->GetScanMs() + " scan ms, " +
            filenode->GetParseMs() + " parse ms)");
    }

    return true;
}
コード例 #12
0
ファイル: export.hpp プロジェクト: xclaeys/ElastoPhi
			infile >> poubelle;
			infile >> Pt;
			Elt[e][j] = num;
			X.push_back(Pt);
			num++;
		}
		
		// Separateur inter-element
		if(e<NbElt-1){infile >> poubelle;}
		
	}
	infile.close();
	
	// Ecriture fichier de sortie
	ofstream outfile;
	outfile.open((GetOutputPath()+"/"+outputname).c_str());
	outfile << "MeshVersionFormatted 1\n";
	outfile << "Dimension 3\n";
	outfile << "Vertices\n";
	outfile << X.size() << endl;
	for(int j=0; j<X.size(); j++){
		outfile << X[j] << "\t" << 0 << "\n";}
	
	if(NbQuad>0){
		outfile << endl;
		outfile << "Quadrilaterals\n";
		outfile << NbQuad << endl;
		for(int j=0; j<NbElt; j++){
			if(NbPt[j]==4){
				for(int k=0; k<4; k++){
					outfile << Elt[j][k]+1 << "\t";