void CCregLoadSaveHandler::SaveGame(const std::string& file)
{
    logOutput.Print("Saving game");
    try {
        std::ofstream ofs(filesystem.LocateFile(file, FileSystem::WRITE).c_str(), std::ios::out|std::ios::binary);
        if (ofs.bad() || !ofs.is_open()) {
            throw content_error("Unable to save game to file \"" + file + "\"");
        }

        std::string scriptText = gameSetup->gameSetupText;

        WriteString(ofs, scriptText);

        WriteString(ofs, modName);
        WriteString(ofs, mapName);

        CGameStateCollector* gsc = new CGameStateCollector();

        creg::COutputStreamSerializer os;
        os.SavePackage(&ofs, gsc, gsc->GetClass());
        PrintSize("Game",ofs.tellp());
        int aistart = ofs.tellp();
        eoh->Save(&ofs);
        PrintSize("AIs", ((int)ofs.tellp())-aistart);
    } catch (content_error& e) {
        logOutput.Print("Save failed(content error): %s", e.what());
    } catch (std::exception& e) {
        logOutput.Print("Save failed: %s", e.what());
    } catch (char*& e) {
        logOutput.Print("Save failed: %s", e);
    } catch (...) {
        logOutput.Print("Save failed(unknown error)");
    }
}
Beispiel #2
0
static void PrintSegments (const cc65_segmentinfo* S)
/* Output a list of segments */
{
    unsigned I;
    const cc65_segmentdata* D;

    /* Segments */
    for (I = 0, D = S->data; I < S->count; ++I, ++D) {
        PrintId (D->segment_id, 8);
        Print ("%-16s", D->segment_name);
        PrintAddr (D->segment_start, 9);
        PrintSize (D->segment_size, 7);
        Print ("%-16s", D->output_name? D->output_name : "");
        PrintSize (D->output_offs, 6);
        NewLine ();
    }
}
void CLoadSaveHandler::SaveGame(std::string file)
{
	LoadStartPicture(teamHandler->Team(gu->myTeam)->side);
	PrintLoadMsg("Saving game");
	try {
		std::ofstream ofs(filesystem.LocateFile(file, FileSystem::WRITE).c_str(), std::ios::out|std::ios::binary);
		if (ofs.bad() || !ofs.is_open()) {
			handleerror(0,"Couldnt save game to file",file.c_str(),0);
			return;
		}

		std::string scriptText;
		if (gameSetup) {
			scriptText = gameSetup->gameSetupText;
		}

		WriteString(ofs, scriptText);

		WriteString(ofs, modName);
		WriteString(ofs, mapName);

		CGameStateCollector *gsc = new CGameStateCollector();

		creg::COutputStreamSerializer os;
		os.SavePackage(&ofs, gsc, gsc->GetClass());
		PrintSize("Game",ofs.tellp());
		int aistart = ofs.tellp();
		for (int a=0;a<MAX_TEAMS;a++)
			grouphandlers[a]->Save(&ofs);
		globalAI->Save(&ofs);
		PrintSize("AIs",((int)ofs.tellp())-aistart);
	} catch (content_error &e) {
		logOutput.Print("Save faild(content error): %s",e.what());
	} catch (std::exception &e) {
		logOutput.Print("Save faild: %s",e.what());
	} catch (char* &e) {
		logOutput.Print("Save faild: %s",e);
	} catch (...) {
		logOutput.Print("Save faild(unknwon error)");
	}
	UnloadStartPicture();
}
Beispiel #4
0
static void PrintScopes (const cc65_scopeinfo* S)
/* Output a list of scopes */
{
    unsigned I;
    const cc65_scopedata* D;

    /* Segments */
    for (I = 0, D = S->data; I < S->count; ++I, ++D) {
        PrintId (D->scope_id, 8);
        Print ("%-24s", D->scope_name);
        PrintNumber (D->scope_type, 4, 8);     /* ## */
        PrintSize (D->scope_size, 8);
        PrintId (D->parent_id, 8);
        PrintId (D->symbol_id, 8);
        PrintId (D->module_id, 0);
        NewLine ();
    }
}
Beispiel #5
0
int ProcessFile(const wchar_t *file_path)
{
    char mbs[MAX_PATH] = { 0 };
    WideCharToMultiByte(CP_ACP, 0, file_path, -1, mbs, sizeof(mbs) - 1, nullptr, nullptr);
    std::cout << "Processing: " << mbs << std::endl;
    std::string filename(mbs);
#else
// written like this in order to be callback funtion of ftw()
int ProcessFile(const char file_path[], const struct stat *sb = nullptr, int typeflag = FTW_F)
{
    if (typeflag != FTW_F)
    {
        return 0;
    }
    std::cout << "Processing: " << file_path << std::endl;
    std::string filename(file_path);
#endif // _WIN32


    File input_file(file_path);

    if (input_file.IsOK())
    {
        size_t original_size = input_file.GetSize();

        size_t new_size = LeanifyFile(input_file.GetFilePionter(), original_size, 0, filename);

        PrintSize(original_size);
        std::cout << " -> ";
        PrintSize(new_size);
        std::cout << "\tLeanified: ";
        PrintSize(original_size - new_size);

        std::cout << " (" << 100 - 100.0 * new_size / original_size << "%)" << std::endl;

        input_file.UnMapFile(new_size);
    }

    return 0;
}


void PauseIfNotTerminal()
{
    // pause if Leanify is not started in terminal
    // so that user can see the output instead of just a flash of a black box
#ifdef _WIN32
    if (is_pause)
    {
        system("pause");
    }
#endif // _WIN32
}



void PrintInfo()
{
    std::cerr << "Leanify\t" << VERSION_STR << std::endl << std::endl;
    std::cerr <<
        "Usage: leanify [options] paths\n"
        "  -i, --iteration <iteration>   More iterations produce better result, but\n"
        "                                  use more time, default is 15.\n"
        "  -d, --max_depth <max depth>   Maximum recursive depth, unlimited by default.\n"
        "                                  Set to 1 will disable recursive minifying.\n"
        "  -f, --fastmode                Fast mode, no recompression.\n"
        "  -q, --quiet                   No output to stdout.\n"
        "  -v, --verbose                 Verbose output.\n"
        "  --keep-exif                   Do not remove Exif.\n";
    PauseIfNotTerminal();
}