Ejemplo n.º 1
0
ADVBConfig::ADVBConfig() : config(AString(DEFAULTCONFDIR).CatPath("dvb"), false),
						   defaults(20, &AString::DeleteString),
						   webresponse(false)
{
	static const struct {
		const char *name;
		const char *value;
	} __defaults[] = {
		{"prehandle",  		 	"2"},
		{"posthandle", 		 	"3"},
		{"pri", 	   		 	"0"},
		{"dir",              	""},
		{"h264crf",      	 	"17"},
		{"maxvideorate", 	 	"2000k"},
		{"aacbitrate", 	 	 	"160k"},
		{"mp3bitrate", 	 	 	"160k"},
		{"copyvideo", 	 	 	"-vcodec copy"},
		{"copyaudio", 	 	 	"-acodec copy"},
		{"mp3audio",  	 	 	"-acodec mp3 -b:a {conf:mp3bitrate}"},
		{"h264preset",   	 	"veryfast"},
		{"h264bufsize",  	 	"3000k"},
		{"videodeinterlace", 	"yadif"},
		{"videofilter",  	 	"-filter:v {conf:videodeinterlace}"},
		{"filters",		 	 	"{conf:videofilter} {conf:audiofilter}"},
		{"encodeflags",	 	 	"-movflags +faststart"},
		{"h264video", 	 	 	"-vcodec libx264 -preset {conf:h264preset} -crf {conf:h264crf} -maxrate {conf:maxvideorate} -bufsize {conf:h264bufsize} {conf:encodeflags} {conf:filters}"},
		{"aacaudio",  	 	 	"-acodec libfdk_aac -b:a {conf:aacbitrate}"},
		{"encodecopy",   	 	"{conf:copyvideo} {conf:mp3audio}"},
		{"encodeh264",   	 	"{conf:h264video} {conf:aacaudio}"},
		{"encodeargs",   	 	"{conf:encodeh264}"},
		{"encodeaudioonlyargs", "{conf:mp3audio}"},
	};
	uint_t i;

	for (i = 0; i < NUMBEROF(__defaults); i++) {
		defaults.Insert(__defaults[i].name, (uptr_t)new AString(__defaults[i].value));
	}

	CreateDirectory(GetConfigDir());
	CreateDirectory(GetDataDir());
	CreateDirectory(GetLogDir());
	CreateDirectory(GetRecordingsStorageDir());
	CreateDirectory(GetRecordingsDir());
	CreateDirectory(GetTempDir());

	if (CommitScheduling()) {
		AList   users;
		AString dir;

		ListUsers(users);

		const AString *user = AString::Cast(users.First());
		while (user) {
			if (((dir = GetRecordingsDir(*user)).Valid())        && (dir.Pos("{") < 0)) CreateDirectory(dir);
			if (((dir = GetRecordingsArchiveDir(*user)).Valid()) && (dir.Pos("{") < 0)) CreateDirectory(dir);

			user = user->Next();
		}
	}
}
Ejemplo n.º 2
0
bool DebugLog::Init(const char *pName, bool bEnable, bool bForceOpen)
{
    wxCriticalSectionLocker lock(m_criticalSection);

    if (m_bEnabled)
    {
        wxFFile::Flush();
        wxFFile::Close();

        m_bEnabled = false;
    }

    if (bEnable && (m_pPathName.IsEmpty() || bForceOpen))
    {
        wxDateTime now = wxDateTime::UNow();

        m_pPathName = GetLogDir() + PATHSEPSTR + "PHD2_DebugLog" + now.Format(_T("_%Y-%m-%d")) +  now.Format(_T("_%H%M%S"))+ ".txt";

        if (!wxFFile::Open(m_pPathName, "a"))
        {
            wxMessageBox(wxString::Format("unable to open file %s", m_pPathName));
        }
    }

    m_bEnabled = bEnable;

    return m_bEnabled;
}
Ejemplo n.º 3
0
ENTERPRISE_VOID_FUNC_2ARG_DEFINE_STUB(void, LogTotalCompliance, const char *, version, int, background_tasks)
{
    double total = (double) (PR_KEPT + PR_NOTKEPT + PR_REPAIRED) / 100.0;

    char string[CF_BUFSIZE] = { 0 };

    snprintf(string, CF_BUFSIZE,
             "Outcome of version %s (" CF_AGENTC "-%d): Promises observed to be kept %.2f%%, Promises repaired %.2f%%, Promises not repaired %.2f%%",
             version, background_tasks,
             (double) PR_KEPT / total,
             (double) PR_REPAIRED / total,
             (double) PR_NOTKEPT / total);

    Log(LOG_LEVEL_VERBOSE, "Logging total compliance, total '%s'", string);

    char filename[CF_BUFSIZE];
    snprintf(filename, CF_BUFSIZE, "%s/%s", GetLogDir(), CF_PROMISE_LOG);
    MapName(filename);

    FILE *fout = fopen(filename, "a");
    if (fout == NULL)
    {
        Log(LOG_LEVEL_ERR, "In total compliance logging, could not open file '%s'. (fopen: %s)", filename, GetErrorStr());
    }
    else
    {
        fprintf(fout, "%jd,%jd: %s\n", (intmax_t)CFSTARTTIME, (intmax_t)time(NULL), string);
        fclose(fout);
    }
}
Ejemplo n.º 4
0
static void LoadSetuid(void)
{
    char filename[CF_BUFSIZE];
    snprintf(filename, CF_BUFSIZE, "%s/cfagent.%s.log", GetLogDir(), VSYSNAME.nodename);
    MapName(filename);

    VSETUIDLIST = RawLoadItemList(filename);
}
Ejemplo n.º 5
0
void RotateLogs()
{
    char tmpNo[3] = {0};
    char baseDirName[256] = {0};
    char oldDirName[256] = {0};
    char newDirName[256] = {0};
    char tmpFileName[256] = {0};

    if (strlen(GetLogDir()) == 0)
        return;

    GetCurrentDirectory(256, baseDirName);
    strcat(baseDirName, "\\");
    strcat(baseDirName, GetLogDir());
    strcat(baseDirName, "\\");

    time_t curtime;
    tm now;
    time(&curtime);
    now = *localtime(&curtime);
    sprintf(newDirName, "%s%d-%d-%d--%d-%d-%d", baseDirName, now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);

    // Create directory from filename
    CreateDirectory(newDirName, NULL);

    // Move previous log files to new directory
    sprintf(tmpFileName, "%s*.txt", baseDirName);
    WIN32_FIND_DATA wfd;
    HANDLE h_find = FindFirstFile(tmpFileName, &wfd);
    while (h_find != INVALID_HANDLE_VALUE)
    {
        sprintf(oldDirName, "%s%s", baseDirName, wfd.cFileName);
        sprintf(newDirName, "%s%d-%d-%d--%d-%d-%d\\%s", baseDirName, now.tm_year+1900, now.tm_mon+1, now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec, wfd.cFileName);
        MoveFile(oldDirName, newDirName);
        if (!FindNextFile(h_find, &wfd))
        {
            FindClose(h_find);
            h_find = INVALID_HANDLE_VALUE;
        }
    }
}
Ejemplo n.º 6
0
static void LoadSetuid(Attributes a)
{
    char filename[CF_BUFSIZE];

    EditDefaults edits = a.edits;
    edits.backup = BACKUP_OPTION_NO_BACKUP;
    edits.maxfilesize = 1000000;

    snprintf(filename, CF_BUFSIZE, "%s/cfagent.%s.log", GetLogDir(), VSYSNAME.nodename);
    MapName(filename);

    if (!LoadFileAsItemList(&VSETUIDLIST, filename, edits))
    {
        Log(LOG_LEVEL_VERBOSE, "Did not find any previous setuid log '%s', creating a new one", filename);
    }
}
Ejemplo n.º 7
0
static void SaveSetuid(void)
{
    char filename[CF_BUFSIZE];
    snprintf(filename, CF_BUFSIZE, "%s/cfagent.%s.log", GetLogDir(), VSYSNAME.nodename);
    MapName(filename);

    PurgeItemList(&VSETUIDLIST, "SETUID/SETGID");

    Item *current = RawLoadItemList(filename);
    if (!ListsCompare(VSETUIDLIST, current))
    {
        RawSaveItemList(VSETUIDLIST, filename, NewLineMode_Unix);
    }

    DeleteItemList(VSETUIDLIST);
    VSETUIDLIST = NULL;
}
Ejemplo n.º 8
0
bool GuidingLog::EnableLogging(void)
{
    if (m_enabled)
        return false;

    bool bError = false;

    try
    {
        wxDateTime now = wxDateTime::Now();
        if (!m_file.IsOpened())
        {
            m_fileName = GetLogDir() + PATHSEPSTR + "PHD2_GuideLog" + now.Format(_T("_%Y-%m-%d")) +
                now.Format(_T("_%H%M%S")) + ".txt";

            if (!m_file.Open(m_fileName, "w"))
            {
                throw ERROR_INFO("unable to open file");
            }
            m_keepFile = false;             // Don't keep it until something meaningful is logged
        }

        assert(m_file.IsOpened());

        m_file.Write(_T("PHD2 version ") FULLVER _T(", Log version ") GUIDELOG_VERSION _T(". Log enabled at ") +
            now.Format(_T("%Y-%m-%d %H:%M:%S")) + "\n");
        Flush();

        m_enabled = true;

        // persist state
        pConfig->Global.SetBoolean("/LoggingMode", m_enabled);

        // dump guiding header if logging enabled during guide
        if (pFrame && pFrame->pGuider->IsGuiding())
            GuidingHeader();
    }
    catch (wxString Msg)
    {
        POSSIBLY_UNUSED(Msg);
        bError = true;
    }

    return bError;
}
Ejemplo n.º 9
0
static PromiseResult SaveSetuid(EvalContext *ctx, Attributes a, Promise *pp)
{
    Attributes b = a;

    b.edits.backup = BACKUP_OPTION_NO_BACKUP;
    b.edits.maxfilesize = 1000000;

    char filename[CF_BUFSIZE];
    snprintf(filename, CF_BUFSIZE, "%s/cfagent.%s.log", GetLogDir(), VSYSNAME.nodename);
    MapName(filename);

    PurgeItemList(ctx, &VSETUIDLIST, "SETUID/SETGID");

    PromiseResult result = PROMISE_RESULT_NOOP;
    if (!CompareToFile(ctx, VSETUIDLIST, filename, a, pp, &result))
    {
        SaveItemListAsFile(VSETUIDLIST, filename, b);
    }

    DeleteItemList(VSETUIDLIST);
    VSETUIDLIST = NULL;

    return result;
}
Ejemplo n.º 10
0
void PATHMANAGER::Init(std::ostream & info_output, std::ostream & error_output)
{
	typedef std::vector<fs::path> Paths;

	// Set Ogre plugins dir
	{
		ogre_plugin_dir = "";
		char *plugindir = getenv("OGRE_PLUGIN_DIR");
		if (plugindir) {
			ogre_plugin_dir = plugindir;
		#ifndef _WIN32
		} else if (fs::exists(fs::path(OGRE_PLUGIN_DIR) / "RenderSystem_GL.so")) {
			ogre_plugin_dir = OGRE_PLUGIN_DIR;
		#endif
		} else {
			#ifdef _WIN32
			ogre_plugin_dir = ".";
			#else
			Paths dirs;
			#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(_M_X64)
			dirs.push_back("/usr/local/lib64");
			dirs.push_back("/usr/lib64");
			#else
			dirs.push_back("/usr/local/lib32");
			dirs.push_back("/usr/lib32");
			#endif
			dirs.push_back("/usr/local");
			dirs.push_back("/usr/lib");
			// Loop through the paths and pick the first one that contain a plugin
			for (Paths::const_iterator p = dirs.begin(); p != dirs.end(); ++p) {
				if (fs::exists(*p / "OGRE/RenderSystem_GL.so")) {
					ogre_plugin_dir = (*p / "OGRE").string();
					break;
				} else if (fs::exists(*p / "ogre/RenderSystem_GL.so")) {
					ogre_plugin_dir = (*p / "ogre").string();
					break;
				}
			}
			#endif
		}
	}

	fs::path shortDir = "stuntrally";
	// Figure out the user's home directory
	{
		home_dir = "";
		#ifndef _WIN32 // POSIX
			char *homedir = getenv("HOME");
			if (homedir == NULL)
			{
				home_dir = "/home/";
				homedir = getenv("USER");
				if (homedir == NULL) {
					homedir = getenv("USERNAME");
					if (homedir == NULL) {
						error_output << "Could not find user's home directory!" << std::endl;
						home_dir = "/tmp/";
					}
				}
			}
		#else // Windows
			char *homedir = getenv("USERPROFILE");
			if (homedir == NULL) homedir = "data"; // WIN 9x/Me
		#endif
		home_dir += homedir;
	}

	// Find user's config dir
	#ifndef _WIN32 // POSIX
	{
		char const* conf = getenv("XDG_CONFIG_HOME");
		if (conf) user_config_dir = (fs::path(conf) / "stuntrally").string();
		else user_config_dir = (fs::path(home_dir) / ".config" / "stuntrally").string();
	}
	#else // Windows
	{
		// Open AppData directory
		std::string str;
		ITEMIDLIST* pidl;
		char AppDir[MAX_PATH];
		HRESULT hRes = SHGetSpecialFolderLocation(NULL, CSIDL_APPDATA|CSIDL_FLAG_CREATE , &pidl);
		if (hRes == NOERROR)
		{
			SHGetPathFromIDList(pidl, AppDir);
			int i;
			for (i = 0; AppDir[i] != '\0'; i++) {
				if (AppDir[i] == '\\') str += '/';
				else str += AppDir[i];
			}
			user_config_dir = (fs::path(str) / "stuntrally").string();
		}
	}
	#endif
	// Create user's config dir
	CreateDir(user_config_dir, error_output);

	// Find user's data dir (for additional data)
	#ifdef _WIN32
	user_data_dir = user_config_dir;  // APPDATA/stuntrally
	#else
	{
		fs::path shareDir = SHARED_DATA_DIR;
		char const* xdg_data_home = getenv("XDG_DATA_HOME");
		user_data_dir = (xdg_data_home ? xdg_data_home / shortDir : fs::path(home_dir) / ".local" / shareDir).string();
	}
	#endif
	// Create user's data dir and its children
	CreateDir(user_data_dir, error_output);
	CreateDir(GetTrackRecordsPath(), error_output);
	CreateDir(GetScreenShotDir(), error_output);
	CreateDir(GetTrackPathUser(), error_output);  // user tracks
	CreateDir(GetTrackPathUser()+"/_previews", error_output);
	CreateDir(GetReplayPath(), error_output);
	CreateDir(GetGhostsPath(), error_output);

	// Find game data dir and defaults config dir
	char *datadir = getenv("STUNTRALLY_DATA_ROOT");
	if (datadir)
		game_data_dir = std::string(datadir);
	else
	{	fs::path shareDir = SHARED_DATA_DIR;
		Paths dirs;

		// Adding users data dir
		// TODO: Disabled for now until this is handled properly
		//dirs.push_back(user_data_dir);

		// Adding relative path from installed executable
		dirs.push_back(execname().parent_path().parent_path() / shareDir);
		// Adding relative path for running from sources
		dirs.push_back(execname().parent_path().parent_path() / "data");
		dirs.push_back(execname().parent_path().parent_path());
		dirs.push_back(execname().parent_path() / "data");
		dirs.push_back(execname().parent_path());
		#ifndef _WIN32
		// Adding XDG_DATA_DIRS
		{
			char const* xdg_data_dirs = getenv("XDG_DATA_DIRS");
			std::istringstream iss(xdg_data_dirs ? xdg_data_dirs : "/usr/local/share/:/usr/share/");
			for (std::string p; std::getline(iss, p, ':'); dirs.push_back(p / shortDir)) {}
		}
		#endif
		// TODO: Adding path from config file

		// Loop through the paths and pick the first one that contain some data
		for (Paths::const_iterator p = dirs.begin(); p != dirs.end(); ++p) {
			// Data dir
			if (fs::exists(*p / "hud")) game_data_dir = p->string();
			// Config dir
			if (fs::exists(*p / "config"))
				game_config_dir = (*p / "config").string();
			// Check if both are found
			if (!game_data_dir.empty() && !game_config_dir.empty()) break;
		}
	}

	// Find cache dir
	#ifdef _WIN32
	cache_dir = user_config_dir + "/cache";  // APPDATA/stuntrally/cache
	#else
	char const* xdg_cache_home = getenv("XDG_CACHE_HOME");
	cache_dir = (xdg_cache_home ? xdg_cache_home / shortDir : fs::path(home_dir) / ".cache" / shortDir).string();
	#endif
	// Create cache dir
	CreateDir(cache_dir, error_output);
	CreateDir(GetShaderCacheDir(), error_output);

	// Print diagnostic info
	std::stringstream out;
	out << "--- Directories: ---" << ogre_plugin_dir << std::endl;
	out << "Ogre plugin:  " << ogre_plugin_dir << std::endl;
	out << "Home:         " << home_dir << std::endl;
	out << "Default cfg:  " << GetGameConfigDir() << std::endl;
	out << "User cfg:     " << GetUserConfigDir() << std::endl;
	out << "Data:         " << GetDataPath() << std::endl;
	out << "User data:    " << GetUserDataDir() << std::endl;
	out << "Cache:        " << GetCacheDir() << std::endl;
	out << "Shader cache: " << GetShaderCacheDir() << std::endl;
	out << "Log:          " << GetLogDir() << std::endl;
	info_output << out.str();
}
Ejemplo n.º 11
0
void GenericAgentInitialize(EvalContext *ctx, GenericAgentConfig *config)
{
    int force = false;
    struct stat statbuf, sb;
    char vbuff[CF_BUFSIZE];
    char ebuff[CF_EXPANDSIZE];

#ifdef __MINGW32__
    InitializeWindows();
#endif

    DetermineCfenginePort();

    EvalContextClassPutHard(ctx, "any", "source=agent");

    GenericAgentAddEditionClasses(ctx);

/* Define trusted directories */

    const char *workdir = GetWorkDir();

    if (!workdir)
    {
        FatalError(ctx, "Error determining working directory");
    }

    OpenLog(LOG_USER);
    SetSyslogFacility(LOG_USER);

    Log(LOG_LEVEL_VERBOSE, "Work directory is %s", workdir);

    snprintf(vbuff, CF_BUFSIZE, "%s%cupdate.conf", GetInputDir(), FILE_SEPARATOR);
    MakeParentDirectory(vbuff, force);
    snprintf(vbuff, CF_BUFSIZE, "%s%cbin%ccf-agent -D from_cfexecd", workdir, FILE_SEPARATOR, FILE_SEPARATOR);
    MakeParentDirectory(vbuff, force);
    snprintf(vbuff, CF_BUFSIZE, "%s%coutputs%cspooled_reports", workdir, FILE_SEPARATOR, FILE_SEPARATOR);
    MakeParentDirectory(vbuff, force);
    snprintf(vbuff, CF_BUFSIZE, "%s%clastseen%cintermittencies", workdir, FILE_SEPARATOR, FILE_SEPARATOR);
    MakeParentDirectory(vbuff, force);
    snprintf(vbuff, CF_BUFSIZE, "%s%creports%cvarious", workdir, FILE_SEPARATOR, FILE_SEPARATOR);
    MakeParentDirectory(vbuff, force);

    snprintf(vbuff, CF_BUFSIZE, "%s%c.", GetLogDir(), FILE_SEPARATOR);
    MakeParentDirectory(vbuff, force);
    snprintf(vbuff, CF_BUFSIZE, "%s%c.", GetPidDir(), FILE_SEPARATOR);
    MakeParentDirectory(vbuff, force);
    snprintf(vbuff, CF_BUFSIZE, "%s%c.", GetStateDir(), FILE_SEPARATOR);
    MakeParentDirectory(vbuff, force);

    MakeParentDirectory(GetLogDir(), force);

    snprintf(vbuff, CF_BUFSIZE, "%s", GetInputDir());

    if (stat(vbuff, &sb) == -1)
    {
        FatalError(ctx, " No access to WORKSPACE/inputs dir");
    }

    /* ensure WORKSPACE/inputs directory has all user bits set (u+rwx) */
    if ((sb.st_mode & 0700) != 0700)
    {
        chmod(vbuff, sb.st_mode | 0700);
    }

    snprintf(vbuff, CF_BUFSIZE, "%s%coutputs", workdir, FILE_SEPARATOR);

    if (stat(vbuff, &sb) == -1)
    {
        FatalError(ctx, " No access to WORKSPACE/outputs dir");
    }

    /* ensure WORKSPACE/outputs directory has all user bits set (u+rwx) */
    if ((sb.st_mode & 0700) != 0700)
    {
        chmod(vbuff, sb.st_mode | 0700);
    }

    const char* const statedir = GetStateDir();

    snprintf(ebuff, sizeof(ebuff), "%s%ccf_procs",
             statedir, FILE_SEPARATOR);
    MakeParentDirectory(ebuff, force);

    if (stat(ebuff, &statbuf) == -1)
    {
        CreateEmptyFile(ebuff);
    }

    snprintf(ebuff, sizeof(ebuff), "%s%ccf_rootprocs",
             statedir, FILE_SEPARATOR);

    if (stat(ebuff, &statbuf) == -1)
    {
        CreateEmptyFile(ebuff);
    }

    snprintf(ebuff, sizeof(ebuff), "%s%ccf_otherprocs",
             statedir, FILE_SEPARATOR);

    if (stat(ebuff, &statbuf) == -1)
    {
        CreateEmptyFile(ebuff);
    }

    snprintf(ebuff, sizeof(ebuff), "%s%cprevious_state%c",
             statedir, FILE_SEPARATOR, FILE_SEPARATOR);
    MakeParentDirectory(ebuff, force);

    snprintf(ebuff, sizeof(ebuff), "%s%cdiff%c",
             statedir, FILE_SEPARATOR, FILE_SEPARATOR);
    MakeParentDirectory(ebuff, force);

    snprintf(ebuff, sizeof(ebuff), "%s%cuntracked%c",
             statedir, FILE_SEPARATOR, FILE_SEPARATOR);
    MakeParentDirectory(ebuff, force);

    snprintf(ebuff, sizeof(ebuff), "%s%cpromise_log%c",
            statedir, FILE_SEPARATOR, FILE_SEPARATOR);
    MakeParentDirectory(ebuff, force);

    OpenNetwork();
    CryptoInitialize();

    CheckWorkingDirectories(ctx);

    /* Initialize keys and networking. cf-key, doesn't need keys. In fact it
       must function properly even without them, so that it generates them! */
    if (config->agent_type != AGENT_TYPE_KEYGEN)
    {
        LoadSecretKeys();
        char *bootstrapped_policy_server = ReadPolicyServerFile(workdir);
        PolicyHubUpdateKeys(bootstrapped_policy_server);
        free(bootstrapped_policy_server);
    }

    size_t cwd_size = PATH_MAX;
    while (true)
    {
        char cwd[cwd_size];
        if (!getcwd(cwd, cwd_size))
        {
            if (errno == ERANGE)
            {
                cwd_size *= 2;
                continue;
            }
            else
            {
                Log(LOG_LEVEL_WARNING,
                    "Could not determine current directory (getcwd: %s)",
                    GetErrorStr());
                break;
            }
        }

        EvalContextSetLaunchDirectory(ctx, cwd);
        break;
    }

    if (!MINUSF)
    {
        GenericAgentConfigSetInputFile(config, GetInputDir(), "promises.cf");
    }

    setlinebuf(stdout);

    if (config->agent_specific.agent.bootstrap_policy_server)
    {
        snprintf(vbuff, CF_BUFSIZE, "%s%cfailsafe.cf", GetInputDir(), FILE_SEPARATOR);

        if (stat(vbuff, &statbuf) == -1)
        {
            GenericAgentConfigSetInputFile(config, GetInputDir(), "failsafe.cf");
        }
        else
        {
            GenericAgentConfigSetInputFile(config, GetInputDir(), vbuff);
        }
    }
}
Ejemplo n.º 12
0
bool TopedApp::OnInit() {
//   DATC = DEBUG_NEW DataCenter();
    initDBLib();
    Toped = DEBUG_NEW tui::TopedFrame( wxT( "wx_Toped" ), wxPoint(50,50), wxSize(1200,900) );

    console::ted_log_ctrl *logWindow = DEBUG_NEW console::ted_log_ctrl(Toped->logwin());
    delete wxLog::SetActiveTarget(logWindow);

    CmdList = Toped->cmdlist();
    // Create the main block parser block - WARNING! blockSTACK structure MUST already exist!
    CMDBlock = DEBUG_NEW parsercmd::cmdMAIN();
    tellstdfunc::initFuncLib(Toped, Toped->view());
    InitInternalFunctions(static_cast<parsercmd::cmdMAIN*>(CMDBlock));

    SetTopWindow(Toped);
    Toped->Show(TRUE);

    GetFontDir();
    if (!LoadFontFile("arial1")) return FALSE;

    GetLogDir();
    if (!GetLogFileName()) return FALSE;
    bool recovery_mode = false;
    if (CheckCrashLog())
    {
        wxMessageDialog* dlg1 = DEBUG_NEW  wxMessageDialog(Toped,
                                wxT("Last session didn't exit normally. Start recovery?"),
                                wxT("Toped"),
                                wxYES_NO | wxICON_WARNING);
        if (wxID_YES == dlg1->ShowModal())
            recovery_mode = true;
        else
            tell_log(console::MT_WARNING,"Recovery rejected.");
        dlg1->Destroy();
        if (!recovery_mode) SaveIgnoredCrashLog();
    }
    if (recovery_mode)
    {
        tell_log(console::MT_WARNING,"Starting recovery ...");
        wxString inputfile;
        inputfile << wxT("#include \"") << logFileName.c_str() << wxT("\"");
        Console->parseCommand(inputfile, false);
        tell_log(console::MT_WARNING,"Exit recovery mode.");
        static_cast<parsercmd::cmdMAIN*>(CMDBlock)->recoveryDone();
        LogFile.init(std::string(logFileName.mb_str()), true);
    }
    else
    {
        LogFile.init(std::string(logFileName.mb_str()));
        //   wxLog::AddTraceMask("thread");
        if (1 < argc)
        {
            wxString inputfile;
            for (int i=1; i<argc; i++)
            {
                inputfile.Clear();
                inputfile << wxT("#include \"") << argv[i] << wxT("\"");
                Console->parseCommand(inputfile);
            }
        }
    }
    tell_log(console::MT_WARNING,"Please report a bugs to [email protected] or [email protected]");
    return TRUE;
}
Ejemplo n.º 13
0
void RotateLogs()
{
	char tmpNo[3] = {0};
	char oldDirNo;
	char baseDirName[256] = {0};
	char oldDirName[256] = {0};
	char newDirName[256] = {0};
	char tmpFileName[256] = {0};

	if (strlen(GetLogDir()) == 0)
		return;

	GetCurrentDirectoryA(256, baseDirName);
	strcat(baseDirName, "\\");
	strcat(baseDirName, GetLogDir());
	strcat(baseDirName, "\\");

	// Delete directory '9'
	strcpy(oldDirName, baseDirName);
	strcat(oldDirName, "9");

	SHFILEOPSTRUCTA fileOp;
	fileOp.hwnd = 0;
	fileOp.wFunc = FO_DELETE;
	fileOp.pFrom = oldDirName;
	fileOp.pTo = NULL;
	fileOp.fFlags = FOF_NOERRORUI + FOF_NOCONFIRMATION;
    fileOp.fAnyOperationsAborted = NULL;
    fileOp.hNameMappings = NULL;
    fileOp.lpszProgressTitle = NULL;

	SHFileOperationA(&fileOp);

	// Age directories 1-8
	for (oldDirNo = 99; oldDirNo > 0; oldDirNo--)
	{
		strcpy(oldDirName, baseDirName);
		_itoa(oldDirNo, tmpNo, 10);
		strcat(oldDirName, tmpNo);
		strcpy(newDirName, baseDirName);
		_itoa(oldDirNo + 1, tmpNo, 10);
		strcat(newDirName, tmpNo);
		MoveFileA(oldDirName, newDirName);
	}

	// Create youngest directory '1'
	CreateDirectoryA(oldDirName, NULL);

	// Move current log files to '1'
	strcpy(oldDirName, baseDirName);
	strcat(oldDirName, "nwnx.txt");
	strcpy(newDirName, baseDirName);
	strcat(newDirName, "1\\nwnx.txt");
	MoveFileA(oldDirName, newDirName);
	strcpy(oldDirName, baseDirName);
	strcat(oldDirName, "nwserverlog1.txt");
	strcpy(newDirName, baseDirName);
	strcat(newDirName, "1\\nwserverlog1.txt");
	MoveFileA(oldDirName, newDirName);
	strcpy(oldDirName, baseDirName);
	strcat(oldDirName, "nwserverError1.txt");
	strcpy(newDirName, baseDirName);
	strcat(newDirName, "1\\nwserverError1.txt");
	MoveFileA(oldDirName, newDirName);

	strcpy(oldDirName, baseDirName);
	strcat(oldDirName, "nwnx_odbc.txt");
	strcpy(newDirName, baseDirName);
	strcat(newDirName, "1\\nwnx_odbc.txt");
	MoveFileA(oldDirName, newDirName);
}
Ejemplo n.º 14
0
bool TopedApp::OnInit() {
//Memory leakages check for Windows
/*  #ifdef _DEBUG
  int tmpDbgFlag;

  HANDLE hLogFile=CreateFile("log.txt",GENERIC_WRITE,FILE_SHARE_WRITE,
    NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE|_CRTDBG_MODE_WNDW|_CRTDBG_MODE_DEBUG);
  _CrtSetReportMode(_CRT_WARN,_CRTDBG_MODE_FILE|_CRTDBG_MODE_DEBUG);
  _CrtSetReportMode(_CRT_ERROR,_CRTDBG_MODE_FILE|_CRTDBG_MODE_WNDW|_CRTDBG_MODE_DEBUG);

  _CrtSetReportFile(_CRT_ASSERT,hLogFile);
  _CrtSetReportFile(_CRT_WARN,hLogFile);
  _CrtSetReportFile(_CRT_ERROR,hLogFile);


  tmpDbgFlag=_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
  tmpDbgFlag|=_CRTDBG_ALLOC_MEM_DF;
  tmpDbgFlag|=_CRTDBG_DELAY_FREE_MEM_DF;
  tmpDbgFlag|=_CRTDBG_LEAK_CHECK_DF;
  _CrtSetDbgFlag(tmpDbgFlag);
  //_CrtSetBreakAlloc(5919);
#endif*/
   DATC = new DataCenter();
   Toped = new tui::TopedFrame( wxT( "wx_Toped" ), wxPoint(50,50), wxSize(1200,900) );

   console::ted_log_ctrl *logWindow = new console::ted_log_ctrl(Toped->logwin());
   delete wxLog::SetActiveTarget(logWindow);

   Browsers = Toped->browsers();
   CmdList = Toped->cmdlist();
   // Create the main block parser block - WARNING! blockSTACK structure MUST already exist!
   CMDBlock = new parsercmd::cmdMAIN();
   InitInternalFunctions(static_cast<parsercmd::cmdMAIN*>(CMDBlock));

   SetTopWindow(Toped);
   Toped->Show(TRUE);

   GetFontDir();
   if (!LoadFontFile("arial1")) return FALSE;

   GetLogDir();
   if (!GetLogFileName()) return FALSE;
   bool recovery_mode = false;
   if (CheckCrashLog())
   {
      wxMessageDialog* dlg1 = new  wxMessageDialog(Toped,
            wxT("Last session didn't exit normally. Start recovery?\n\n WARNING! Recovery mode is experimental.\nMake sure that you've backed-up your database before proceeding"),
            wxT("Toped"),
            wxYES_NO | wxICON_WARNING);
      if (wxID_YES == dlg1->ShowModal())
         recovery_mode = true;
      else
         tell_log(console::MT_WARNING,"Recovery rejected.");
      dlg1->Destroy();
      if (!recovery_mode) SaveIgnoredCrashLog();
   }
   if (recovery_mode)
   {
      tell_log(console::MT_WARNING,"Starting recovery ...");
      wxString inputfile;
      inputfile << wxT("#include \"") << logFileName.c_str() << wxT("\"");
      Console->parseCommand(inputfile, false);
      tell_log(console::MT_WARNING,"Previous session recovered.");
      static_cast<parsercmd::cmdMAIN*>(CMDBlock)->recoveryDone();
      LogFile.init(std::string(logFileName.mb_str()), true);
   }
   else
   {
      LogFile.init(std::string(logFileName.mb_str()));
      //   wxLog::AddTraceMask("thread");
      if (1 < argc) 
      {
         wxString inputfile;
         for (int i=1; i<argc; i++)
         {
            inputfile.Clear();
            inputfile << wxT("#include \"") << argv[i] << wxT("\"");
            Console->parseCommand(inputfile);
         }
      }
   }
   return TRUE;
}