#include <sys/types.h>
#include <pwd.h>
#endif
+#ifdef OS_WIN32
+#include <io.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <windows.h>
+#endif
-const char * GetUserName()
+const char * MoonshotGetUserName()
{
#ifdef HAVE_GETPWUID
struct passwd *pwd = getpwuid(getuid());
{
return MOONSHOT_FLATSTORE_USERS;
}
+
+#ifdef OS_WIN32
+static int con_to_std(DWORD std_id, FILE *fp_out)
+{
+ HANDLE con_handle;
+ int fd;
+ FILE *fp;
+ con_handle = GetStdHandle(std_id);
+ if (con_handle == INVALID_HANDLE_VALUE)
+ return 0;
+ fd = _open_osfhandle((intptr_t)con_handle, _O_TEXT);
+ if (fd == -1)
+ return 0;
+ fp = _fdopen(fd, "w" );
+ if (fp == NULL)
+ return 0;
+ *fp_out = *fp;
+ setvbuf(fp_out, NULL, _IONBF, 0 );
+ return 1;
+}
+
+int moonshot_attach_console()
+{
+#if 0
+ if (AttachConsole(ATTACH_PARENT_PROCESS) != 0) {
+ if (con_to_std(STD_OUTPUT_HANDLE, stdout) &&
+ con_to_std(STD_ERROR_HANDLE, stderr)) {
+ return 1;
+ }
+ }
+#endif
+ if (AllocConsole() && AttachConsole(GetCurrentProcessId())) {
+ if (con_to_std(STD_OUTPUT_HANDLE, stdout) &&
+ con_to_std(STD_ERROR_HANDLE, stderr)) {
+ return 1;
+ }
+ }
+
+ return 0;
+}
+#endif
+
static bool explicitly_launched = true;
static bool use_flat_file_store = false;
+static bool attach_console = false;
const GLib.OptionEntry[] options = {
+ {"attach-console",0,0,GLib.OptionArg.NONE,
+ ref attach_console,"attach console",null},
{"dbus-launched",0,GLib.OptionFlags.REVERSE,GLib.OptionArg.NONE,
ref explicitly_launched,"launch for dbus rpc use",null},
{"flat-file-store",0,0,GLib.OptionArg.NONE,
{null}
};
+public extern int moonshot_attach_console();
public static int main(string[] args){
#if IPC_MSRPC
Gtk.Settings settings = Gtk.Settings.get_default ();
settings.set_string_property ("gtk-theme-name", "ms-windows", "moonshot");
settings.set_long_property ("gtk-menu-images", 0, "moonshot");
+ if (attach_console) {
+ if (moonshot_attach_console() != 0) {
+ stdout.printf(_("Attached console\n"));
+ stdout.flush();
+ }
+ }
+ else {
+ stdout.printf("Standard output\n");
+ stdout.flush();
+ }
#endif
Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
}
}
-public extern unowned string GetUserName();
+public extern unowned string MoonshotGetUserName();
public extern unowned string GetFlatStoreUsersFilePath();
public bool UserForcesFlatFileStore()
{
- string username = GetUserName();
+ string username = MoonshotGetUserName();
string flatstore_users_filename = GetFlatStoreUsersFilePath();
FileStream flatstore_users = FileStream.open(flatstore_users_filename, "r");
if (flatstore_users == null) {
string always_confirm;
}
+ [CCode (cname = "moonshot_attach_console")]
+ public extern uint32 attach_console();
+
[CCode (cname = "c_moonshot_show_ui_rpc")]
public extern void show_ui();