コード例 #1
0
ファイル: init-ccnet.c プロジェクト: Jack-Tsue/seafile
/* Copy manual from install dir to Seafile directory */
void
copy_user_manual ()
{
    char *installdir;            /* C:\Program Files\Seafile */
    char *seafdir;              /* C:\Seafile */
    char *src_path;             /* C:\Program Files\Seafile\help.txt */
    char *dst_path;             /* C:\Seafile\help.txt */

    wchar_t *src_path_w, *dst_path_w;

    installdir = g_path_get_dirname (seafile_bin_dir);
    seafdir = g_path_get_dirname (applet->seafile_dir);

    src_path = g_build_filename (installdir, _("Seafile help.txt"), NULL);
    dst_path = g_build_filename (seafdir, _("Seafile help.txt"), NULL);

    src_path_w = wchar_from_utf8 (src_path);
    dst_path_w = wchar_from_utf8 (dst_path);

    BOOL failIfExist = FALSE;
    CopyFileW (src_path_w, dst_path_w, failIfExist);

    g_free (installdir);
    g_free (seafdir);
    g_free (src_path);
    g_free (dst_path);
    g_free (src_path_w);
    g_free (dst_path_w);
}
コード例 #2
0
HANDLE WINAPI flac_internal_CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
#if _MSC_VER > 1900 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
	wchar_t *wname;
	HANDLE handle = INVALID_HANDLE_VALUE;

	if ((wname = wchar_from_utf8(lpFileName)) != NULL) {

		handle = CreateFile2(wname, dwDesiredAccess, dwShareMode, CREATE_ALWAYS, NULL);
		free(wname);
	}

	return handle;
#else
	if (!utf8_filenames) {
		return CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
	} else {
		wchar_t *wname;
		HANDLE handle = INVALID_HANDLE_VALUE;

		if ((wname = wchar_from_utf8(lpFileName)) != NULL) {
			handle = CreateFileW(wname, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
			free(wname);
		}

		return handle;
	}
#endif
}
コード例 #3
0
ファイル: init-ccnet.c プロジェクト: Jack-Tsue/seafile
static void
InitComboxList(HWND hDlg)
{
    HWND hwndGroupsBox = GetDlgItem(hDlg, IDC_COMBOX_DISK);
    wchar_t drives[SEAF_PATH_MAX];
    wchar_t *p;
    ULARGE_INTEGER free_space;
    ULARGE_INTEGER largest_free_space;
    int i = 0;
    int largest_disk_index = 0;

    largest_free_space.QuadPart = 0;
    SendMessage (hwndGroupsBox, CB_RESETCONTENT, 0, 0);

    GetLogicalDriveStringsW (sizeof(drives), drives);
    for (p = drives; *p != L'\0'; p += wcslen(p) + 1) {
        /* Skip floppy disk, network drive, etc */
        if (GetDriveTypeW(p) != DRIVE_FIXED)
            continue;

        if (GetDiskFreeSpaceExW (p, &free_space, NULL, NULL)) {
            if (free_space.QuadPart > largest_free_space.QuadPart) {
                largest_free_space.QuadPart = free_space.QuadPart;
                largest_disk_index = i;
            }
        } else {
            free_space.QuadPart = 0;
            applet_warning ("failed to GetDiskFreeSpaceEx(), GLE=%lu\n",
                            GetLastError());
        }

        wchar_t wbuf[128];
        wchar_t *trans;

        if (free_space.QuadPart) {
            double space = ((double)(free_space.QuadPart)) / (1024 * 1024 * 1024);

            trans = wchar_from_utf8 (_("free"));
            _snwprintf (wbuf, sizeof(wbuf) / sizeof(wchar_t),
                       L"%s\t   (%.1f GB %s)",
                       p, space, trans);
        } else {
            trans = wchar_from_utf8 (_("free space unknown"));
            _snwprintf (wbuf, sizeof(wbuf), L"%s\t   (%s)", p, trans);
        }
        g_free (trans);

        i++;

        SendMessageW (hwndGroupsBox, CB_ADDSTRING, 0, (LPARAM) wbuf);
    }

    SendDlgItemMessage (hDlg, IDC_COMBOX_DISK, CB_SETCURSEL, largest_disk_index, 0);
}
コード例 #4
0
ファイル: vc-utils.c プロジェクト: 2bj/seafile
static gboolean
do_check_file_locked (const char *path, const char *worktree)
{
    char *real_path;
    HANDLE handle;
    wchar_t *path_w;

    real_path = g_build_path(PATH_SEPERATOR, worktree, path, NULL);
    path_w = wchar_from_utf8 (real_path);
    g_free (real_path);

    handle = CreateFileW (path_w,
                          GENERIC_WRITE,
                          0,
                          NULL,
                          OPEN_EXISTING,
                          0,
                          NULL);
    g_free (path_w);
    if (handle != INVALID_HANDLE_VALUE) {
        CloseHandle (handle);
    } else if (GetLastError() == ERROR_SHARING_VIOLATION) {
        return TRUE;
    }

    return FALSE;
}
コード例 #5
0
ファイル: win_utf8_io.c プロジェクト: Audacity-Team/Audacity
int fprintf_utf8(FILE *stream, const char *format, ...)
{
	char *utmp = NULL;
	wchar_t *wout = NULL;
	int ret = -1;

	while (1) {
		va_list argptr;
		if (!(utmp = (char *)malloc(32768*sizeof(char)))) break;
		va_start(argptr, format);
		ret = vsprintf(utmp, format, argptr);
		va_end(argptr);
		if (ret < 0) break;
		if (!(wout = wchar_from_utf8(utmp))) {
			ret = -1;
			break;
		}
		ret = print_console(stream, wout, wcslen(wout));
		break;
	}
	if (utmp) free(utmp);
	if (wout) free(wout);

	return ret;
}
コード例 #6
0
int printf_utf8(const char *format, ...)
{
	char *utmp = NULL;
	wchar_t *wout = NULL;
	int ret = -1;

	while (1) {
		va_list argptr;
		if (!(utmp = (char *)malloc(UTF8_BUFFER_SIZE*sizeof(char)))) break;
		va_start(argptr, format);
		ret = local_vsnprintf(utmp, UTF8_BUFFER_SIZE, format, argptr);
		va_end(argptr);
		if (ret < 0) break;
		if (!(wout = wchar_from_utf8(utmp))) {
			ret = -1;
			break;
		}
		ret = print_console(stdout, wout, wcslen(wout));
		break;
	}
	if (utmp) free(utmp);
	if (wout) free(wout);

	return ret;
}
コード例 #7
0
ファイル: wt-monitor-win32.c プロジェクト: aducode/seafile
static HANDLE add_watch (SeafWTMonitorPriv *priv,
                         const char *repo_id,
                         const char *worktree)
{
    HANDLE dir_handle = NULL;
    wchar_t *path = NULL;
    RepoWatchInfo *info;

    /* worktree is in utf8, need to convert to wchar in win32 */
    path = wchar_from_utf8 (worktree);

    dir_handle = get_handle_of_path (path);
    if (!dir_handle) {
        seaf_warning ("failed to open handle for worktree "
                      "of repo  %s\n", repo_id);
        g_free (path);
        return NULL;
    }
    g_free (path);

    pthread_mutex_lock (&priv->hash_lock);
    g_hash_table_insert (priv->handle_hash,
                         g_strdup(repo_id), (gpointer)(long)dir_handle);

    info = create_repo_watch_info (repo_id, worktree);
    g_hash_table_insert (priv->info_hash, (gpointer)(long)dir_handle, info);
    pthread_mutex_unlock (&priv->hash_lock);

    add_event_to_queue (info->status, WT_EVENT_CREATE_OR_UPDATE, "", NULL);

    return dir_handle;
}
コード例 #8
0
ファイル: win_utf8_io.c プロジェクト: Audacity-Team/Audacity
FILE *fopen_utf8(const char *filename, const char *mode)
{
	wchar_t *wname = NULL;
	wchar_t *wmode = NULL;
	FILE *f = NULL;

	while (1) {
		if (!(wname = wchar_from_utf8(filename))) break;
		if (!(wmode = wchar_from_utf8(mode))) break;
		f = _wfopen(wname, wmode);
		break;
	}
	if (wname) free(wname);
	if (wmode) free(wmode);

	return f;
}
コード例 #9
0
ファイル: win_utf8_io.c プロジェクト: Audacity-Team/Audacity
int rename_utf8(const char *oldname, const char *newname)
{
	wchar_t *wold = NULL;
	wchar_t *wnew = NULL;
	int ret = -1;

	while (1) {
		if (!(wold = wchar_from_utf8(oldname))) break;
		if (!(wnew = wchar_from_utf8(newname))) break;
		ret = _wrename(wold, wnew);
		break;
	}
	if (wold) free(wold);
	if (wnew) free(wnew);

	return ret;
}
コード例 #10
0
ファイル: trayicon.c プロジェクト: pombredanne/seafile
void
trayicon_set_tooltip (SeafileTrayIcon *icon, char *tooltip,
                      int balloon, char *title,
                      unsigned int timeout)
{
    wchar_t *tip_w = NULL;
    wchar_t *title_w = NULL;

    if (tooltip) {
        tip_w = wchar_from_utf8 (tooltip ? tooltip : "");
        if (!tip_w) {
            goto out;
        }
    }

    if (title) {
        title_w = wchar_from_utf8 (title ? title : "");
        if (!title_w) {
            goto out;
        }
    }

    icon->nid.cbSize = sizeof(NOTIFYICONDATAW);
    if (balloon) {
        icon->nid.uFlags      = NIF_INFO;
        icon->nid.uTimeout    = timeout;
        icon->nid.dwInfoFlags = NIIF_INFO;

        safe_wcsncpy (icon->nid.szInfo, tip_w,
                        sizeof(icon->nid.szInfo) / sizeof(wchar_t));
        safe_wcsncpy (icon->nid.szInfoTitle, title_w,
                        sizeof(icon->nid.szInfoTitle) / sizeof(wchar_t));

    } else {
        icon->nid.uFlags = NIF_TIP;
        safe_wcsncpy (icon->nid.szInfo, tip_w,
                        sizeof(icon->nid.szInfo) / sizeof(wchar_t));
    }

    Shell_NotifyIconW(NIM_MODIFY, &(icon->nid));
out:
    g_free (tip_w);
    g_free (title_w);
}
コード例 #11
0
ファイル: win_utf8_io.c プロジェクト: Audacity-Team/Audacity
int unlink_utf8(const char *filename)
{
	wchar_t *wname;
	int ret;

	if (!(wname = wchar_from_utf8(filename))) return -1;
	ret = _wunlink(wname);
	free(wname);

	return ret;
}
コード例 #12
0
ファイル: win_utf8_io.c プロジェクト: Audacity-Team/Audacity
int _stat64_utf8(const char *path, struct __stat64 *buffer)
{
	wchar_t *wpath;
	int ret;

	if (!(wpath = wchar_from_utf8(path))) return -1;
	ret = _wstat64(wpath, buffer);
	free(wpath);

	return ret;
}
コード例 #13
0
ファイル: win_utf8_io.c プロジェクト: Audacity-Team/Audacity
int chmod_utf8(const char *filename, int pmode)
{
	wchar_t *wname;
	int ret;

	if (!(wname = wchar_from_utf8(filename))) return -1;
	ret = _wchmod(wname, pmode);
	free(wname);

	return ret;
}
コード例 #14
0
ファイル: windows_unicode_filenames.c プロジェクト: xiph/flac
FILE* flac_internal_fopen_utf8(const char *filename, const char *mode)
{
	if (!utf8_filenames) {
		return fopen(filename, mode);
	} else {
		wchar_t *wname = NULL;
		wchar_t *wmode = NULL;
		FILE *f = NULL;

		do {
			if (!(wname = wchar_from_utf8(filename))) break;
			if (!(wmode = wchar_from_utf8(mode))) break;
			f = _wfopen(wname, wmode);
		} while(0);

		free(wname);
		free(wmode);

		return f;
	}
}
コード例 #15
0
ファイル: win_utf8_io.c プロジェクト: Audacity-Team/Audacity
HANDLE WINAPI CreateFile_utf8(const char *lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
	wchar_t *wname;
	HANDLE handle = INVALID_HANDLE_VALUE;

	if ((wname = wchar_from_utf8(lpFileName)) != NULL) {
		handle = CreateFileW(wname, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
		free(wname);
	}

	return handle;
}
コード例 #16
0
ファイル: windows_unicode_filenames.c プロジェクト: xiph/flac
int flac_internal_rename_utf8(const char *oldname, const char *newname)
{
	if (!utf8_filenames) {
		return rename(oldname, newname);
	} else {
		wchar_t *wold = NULL;
		wchar_t *wnew = NULL;
		int ret = -1;

		do {
			if (!(wold = wchar_from_utf8(oldname))) break;
			if (!(wnew = wchar_from_utf8(newname))) break;
			ret = _wrename(wold, wnew);
		} while(0);

		free(wold);
		free(wnew);

		return ret;
	}
}
コード例 #17
0
ファイル: windows_unicode_filenames.c プロジェクト: xiph/flac
int flac_internal_unlink_utf8(const char *filename)
{
	if (!utf8_filenames) {
		return _unlink(filename);
	} else {
		wchar_t *wname;
		int ret;

		if (!(wname = wchar_from_utf8(filename))) return -1;
		ret = _wunlink(wname);
		free(wname);

		return ret;
	}
}
コード例 #18
0
ファイル: windows_unicode_filenames.c プロジェクト: xiph/flac
int flac_internal_stat64_utf8(const char *path, struct __stat64 *buffer)
{
	if (!utf8_filenames) {
		return _stat64(path, buffer);
	} else {
		wchar_t *wpath;
		int ret;

		if (!(wpath = wchar_from_utf8(path))) return -1;
		ret = _wstat64(wpath, buffer);
		free(wpath);

		return ret;
	}
}
コード例 #19
0
ファイル: windows_unicode_filenames.c プロジェクト: xiph/flac
int flac_internal_chmod_utf8(const char *filename, int pmode)
{
	if (!utf8_filenames) {
		return _chmod(filename, pmode);
	} else {
		wchar_t *wname;
		int ret;

		if (!(wname = wchar_from_utf8(filename))) return -1;
		ret = _wchmod(wname, pmode);
		free(wname);

		return ret;
	}
}
コード例 #20
0
ファイル: windows_unicode_filenames.c プロジェクト: xiph/flac
int flac_internal_utime_utf8(const char *filename, struct utimbuf *times)
{
	if (!utf8_filenames) {
		return utime(filename, times);
	} else {
		wchar_t *wname;
		struct __utimbuf64 ut;
		int ret;

		if (!(wname = wchar_from_utf8(filename))) return -1;
		ut.actime = times->actime;
		ut.modtime = times->modtime;
		ret = _wutime64(wname, &ut);
		free(wname);

		return ret;
	}
}
コード例 #21
0
ファイル: init-ccnet.c プロジェクト: Jack-Tsue/seafile
BOOL
msgbox_yes_or_no (HWND hWnd, char *format, ...)
{
    va_list params;
    char buf[2048];
    wchar_t *wbuf;
    int res;

    va_start(params, format);
    vsnprintf(buf, sizeof(buf), format, params);
    va_end(params);

    wbuf = wchar_from_utf8 (buf);
    res = MessageBoxW (hWnd, wbuf, L"Seafile", MB_ICONQUESTION | MB_YESNO);

    g_free (wbuf);
    return (res == IDYES);
}
コード例 #22
0
ファイル: win_utf8_io.c プロジェクト: Audacity-Team/Audacity
int utime_utf8(const char *filename, struct utimbuf *times)
{
	wchar_t *wname;
	struct __utimbuf64 ut;
	int ret;

	if (sizeof(*times) == sizeof(ut)) {
		memcpy(&ut, times, sizeof(ut));
	} else {
		ut.actime = times->actime;
		ut.modtime = times->modtime;
	}

	if (!(wname = wchar_from_utf8(filename))) return -1;
	ret = _wutime64(wname, &ut);
	free(wname);

	return ret;
}
コード例 #23
0
int vfprintf_utf8(FILE *stream, const char *format, va_list argptr)
{
	char *utmp = NULL;
	wchar_t *wout = NULL;
	int ret = -1;

	while (1) {
		if (!(utmp = (char *)malloc(UTF8_BUFFER_SIZE*sizeof(char)))) break;
		if ((ret = local_vsnprintf(utmp, UTF8_BUFFER_SIZE, format, argptr)) < 0) break;
		if (!(wout = wchar_from_utf8(utmp))) {
			ret = -1;
			break;
		}
		ret = print_console(stream, wout, wcslen(wout));
		break;
	}
	if (utmp) free(utmp);
	if (wout) free(wout);

	return ret;
}
コード例 #24
0
ファイル: vc-utils.c プロジェクト: Guilhem30/seafile
static gboolean
check_file_locked (const char *path)
{
    HANDLE handle;
    wchar_t *path_w;

    path_w = wchar_from_utf8 (path);

    handle = CreateFileW (path_w,
                          GENERIC_WRITE,
                          0,
                          NULL,
                          OPEN_EXISTING,
                          0,
                          NULL);
    g_free (path_w);
    if (handle != INVALID_HANDLE_VALUE) {
        CloseHandle (handle);
    } else if (GetLastError() == ERROR_SHARING_VIOLATION) {
        return TRUE;
    }

    return FALSE;
}
コード例 #25
0
ファイル: init-ccnet.c プロジェクト: Jack-Tsue/seafile
/* 1. set seafile-data directory to hidden
   2. set seafile folder icon (via Desktop.ini)
*/
static void
set_seafdir_attributes ()
{
    char *seafdir = g_path_get_dirname (applet->seafile_dir);
    char *icon_path = NULL;
    char *ini_file_path = NULL;

    wchar_t *seafile_dir_w = NULL; /* C:\\Seafile\\seafile-data */
    wchar_t *seafdir_w =  NULL;    /* C:\\Seafile */
    wchar_t *icon_path_w = NULL; /* C:\\Program Files\\Seafile\\bin\\seafdir.ico */
    wchar_t * ini_file_path_w = NULL; /* C:\\Seafile\\Desktop.ini */

    FILE *ini_file = NULL;

    seafile_dir_w = wchar_from_utf8 (applet->seafile_dir);
    seafdir_w = wchar_from_utf8 (seafdir);

    /* Make seafile-data directory hidden. */
    SetFileAttributesW (seafile_dir_w,
                        FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);

    /* Set seafdir folder icon. */
    SetFileAttributesW (seafdir_w, FILE_ATTRIBUTE_SYSTEM);
    ini_file_path = g_build_filename (seafdir, "Desktop.ini", NULL);
    ini_file_path_w = wchar_from_utf8 (ini_file_path);

    if (!(ini_file = g_fopen(ini_file_path, "w"))) {
        applet_warning ("failed to open %s\n", ini_file_path);
        goto out;
    }

    icon_path = g_build_filename (seafile_bin_dir, "seafdir.ico", NULL);

    char *ptr = icon_path;
    while (*ptr != '\0') {
        /* Replace all / with \ */
        if (*ptr == '/')
            *ptr = '\\';

        ptr++;
    }
    icon_path_w = wchar_from_utf8 (icon_path);

    fwprintf (ini_file, L"[.ShellClassInfo]\n");
    fwprintf (ini_file, L"IconFile=%s\n", icon_path_w);
    fwprintf (ini_file, L"IconIndex=0\n");

    /* Make the "Desktop.ini" file hidden. */
    SetFileAttributesW (ini_file_path_w,
                        FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM);

out:
    g_free (seafile_dir_w);
    g_free (seafdir);
    g_free (seafdir_w);
    g_free (ini_file_path);
    g_free (ini_file_path_w);
    g_free (icon_path);
    g_free (icon_path_w);

    if (ini_file) fclose (ini_file);
}
コード例 #26
0
ファイル: init-ccnet.c プロジェクト: Jack-Tsue/seafile
static BOOL CALLBACK
InitSeafileProc (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    int len;
    char seafiledir[SEAF_PATH_MAX];

    memset(seafiledir, 0, sizeof(seafiledir));

    switch (message) {
    case WM_CREATE:
        break;

    case WM_INITDIALOG: {
        InitComboxList(hDlg);
        set_dlg_icon (hDlg, IDI_SEAFILE_ICON);
        wchar_t *msg =  wchar_from_utf8(_("Choose a disk"));
        SetWindowTextW (GetDlgItem(hDlg, IDC_STATIC_TITLE), msg);
        wchar_t *title = wchar_from_utf8(_("Seafile Initialization"));
        SetWindowTextW (hDlg, title);
        g_free (msg);
        g_free (title);
                       
        set_control_font (GetDlgItem(hDlg, IDC_STATIC_TITLE), "Courier");
        make_wnd_foreground(hDlg);
        return TRUE;
        break;
    }

    case WM_CTLCOLORSTATIC:
        if (IS_DLG_CONTROL (IDC_STATIC_TITLE)) {

            SetBkMode((HDC)wParam, TRANSPARENT);
            return (BOOL)GetStockObject(NULL_BRUSH);
        }
        break;

    case WM_COMMAND:
        switch(LOWORD(wParam)) {
        case IDOK: {
            len = GetWindowText (GetDlgItem(hDlg,IDC_COMBOX_DISK),
                                 seafiledir, sizeof(seafiledir));
            seafiledir[len] = '\0';
            int i = 0;
            while (seafiledir[i] != '\t')
                i++;

            seafiledir[i] = '\0';

            applet->seafile_dir = g_build_filename(seafiledir,
                                                   "Seafile",
                                                   "seafile-data", NULL);

            if (checkdir_with_mkdir(applet->seafile_dir) < 0) {
                g_free (applet->seafile_dir);
                applet->seafile_dir = NULL;
                EndDialog (hDlg, INIT_CCNET_FAILED);
                return TRUE;
            }

            set_seafdir_attributes ();
            EndDialog (hDlg, INIT_CCNET_SUCCESS);
            return TRUE;
        }

        case IDCANCEL:
            if (msgbox_yes_or_no (hDlg, _("Initialzation is not finished. Really quit?"))) {
                EndDialog (hDlg, INIT_CCNET_FAILED);
            }
            return TRUE;
        default:
            break;
        }
        break;

    case WM_CLOSE:
        if (msgbox_yes_or_no (hDlg, _("Initialzation is not finished. Really quit?"))) {
            EndDialog (hDlg, INIT_CCNET_FAILED);
        }
        return TRUE;

    default:
        break;
    }
    return 0;
}