QString TileMapAdapter::query(int x, int y, int z) const
    {
        x = xoffset(x);
        y = yoffset(y);

        int a[3] = {z, x, y};
        return QString(serverPath().replace(order[2][0],2, loc.toString(a[order[2][1]]))
                .replace(order[1][0],2, loc.toString(a[order[1][1]]))
                .replace(order[0][0],2, loc.toString(a[order[0][1]])));

    }
status_t
GeneralView::Save()
{
	BPath path;

	status_t ret = B_OK;
	ret = find_directory(B_USER_SETTINGS_DIRECTORY, &path);
	if (ret != B_OK)
		return ret;

	path.Append(kSettingsDirectory);
	path.Append(kGeneralSettings);

	BMessage settings;

	bool autoStart = (fAutoStart->Value() == B_CONTROL_ON);
	settings.AddBool(kAutoStartName, autoStart);

	int32 timeout = atol(fTimeout->Text());
	settings.AddInt32(kTimeoutName, timeout);

	// Save settings file
	BFile file(path.Path(), B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
	ret = settings.Flatten(&file);
	if (ret != B_OK) {
		BAlert* alert = new BAlert("",
			B_TRANSLATE("An error occurred saving the preferences.\n"
				"It's possible you are running out of disk space."),
			B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
		(void)alert->Go();
		return ret;
	}

	// Find server path
	entry_ref ref;
	if (!_CanFindServer(&ref)) {
		BAlert* alert = new BAlert("",
			B_TRANSLATE("The notifications server cannot be found.\n"
			   "A possible cause is an installation not done correctly"),
			B_TRANSLATE("OK"), NULL, NULL, B_WIDTH_AS_USUAL, B_STOP_ALERT);
		(void)alert->Go();
		return B_ERROR;
	}

	// UserBootscript command
	BPath serverPath(&ref);

	// Start server at boot time
	ret = find_directory(B_USER_BOOT_DIRECTORY, &path, true);
	if (ret != B_OK) {
		BAlert* alert = new BAlert("",
			B_TRANSLATE("Can't save preferences, you probably don't have "
			"write access to the boot settings directory."), B_TRANSLATE("OK"),
			NULL, NULL,
			B_WIDTH_AS_USUAL, B_STOP_ALERT);
		(void)alert->Go();
		return ret;
	}

	path.Append("launch");
	BDirectory directory(path.Path());
	BEntry entry(&directory, serverPath.Leaf());

	// Remove symbolic link
	entry.Remove();

	if (autoStart) {
		// Put a symlink into ~/config/boot/launch
		if ((ret = directory.CreateSymLink(serverPath.Leaf(),
			serverPath.Path(), NULL) != B_OK)) {
			BAlert* alert = new BAlert("",
				B_TRANSLATE("Can't enable notifications at startup time, "
				"you probably don't have write permission to the boot settings"
				" directory."), B_TRANSLATE("OK"), NULL, NULL,
				B_WIDTH_AS_USUAL, B_STOP_ALERT);
			(void)alert->Go();
			return ret;
		}
	}

	return B_OK;
}
Beispiel #3
0
static bool launch_server()
{
	EZDBGONLYLOGGERPRINT("Launching weasel server.");

	// 從註冊表取得server位置
	HKEY hKey;
	LSTATUS ret = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WEASEL_REG_KEY, 0, KEY_READ | KEY_WOW64_32KEY, &hKey);
	if (ret != ERROR_SUCCESS)
	{
		error_message(L"註冊表信息無影了");
		return false;
	}

	WCHAR value[MAX_PATH];
	DWORD len = sizeof(value);
	DWORD type = 0;
	ret = RegQueryValueEx(hKey, L"WeaselRoot", NULL, &type, (LPBYTE)value, &len);
	if (ret != ERROR_SUCCESS)
	{
		error_message(L"未設置 WeaselRoot");
		RegCloseKey(hKey);
		return false;
	}
	wpath weaselRoot(value);

	len = sizeof(value);
	type = 0;
	ret = RegQueryValueEx(hKey, L"ServerExecutable", NULL, &type, (LPBYTE)value, &len);
	if (ret != ERROR_SUCCESS)
	{
		error_message(L"未設置 ServerExecutable");
		RegCloseKey(hKey);
		return false;
	}
	wpath serverPath(weaselRoot / value);

	RegCloseKey(hKey);

	// 啓動服務進程
	wstring exe = serverPath.native_file_string();
	wstring dir = weaselRoot.native_file_string();

	STARTUPINFO startup_info = {0};
	PROCESS_INFORMATION process_info = {0};
	startup_info.cb = sizeof(startup_info);

	if (!CreateProcess(exe.c_str(), NULL, NULL, NULL, FALSE, 0, NULL, dir.c_str(), &startup_info, &process_info))
	{
		EZDBGONLYLOGGERPRINT("ERROR: failed to launch weasel server.");
		error_message(L"服務進程啓動不起來 :(");
		return false;
	}

	if (!WaitForInputIdle(process_info.hProcess, 1500))
	{
		EZDBGONLYLOGGERPRINT("WARNING: WaitForInputIdle() timed out; succeeding IPC messages might not be delivered.");
	}
	if (process_info.hProcess) CloseHandle(process_info.hProcess);
	if (process_info.hThread) CloseHandle(process_info.hThread);

	return true;
}