Mercurial > hg > nnchat
comparison main.c @ 661:eb3692d85ac2
Use TH_PLAT_WINDOWS for preprocessor conditionals.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 12 Feb 2016 01:40:04 +0200 |
parents | 8b8ef14d7177 |
children | 0c94af18f55e |
comparison
equal
deleted
inserted
replaced
660:41bfde66634d | 661:eb3692d85ac2 |
---|---|
8 #include "th_network.h" | 8 #include "th_network.h" |
9 #include "util.h" | 9 #include "util.h" |
10 #include "ui.h" | 10 #include "ui.h" |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 #include <fcntl.h> | 12 #include <fcntl.h> |
13 #ifdef __WIN32 | 13 #ifdef TH_PLAT_WINDOWS |
14 # include <shlwapi.h> | 14 # include <shlwapi.h> |
15 # include <shfolder.h> | 15 # include <shfolder.h> |
16 #else | 16 #else |
17 # include <sys/wait.h> | 17 # include <sys/wait.h> |
18 # include <sys/stat.h> | 18 # include <sys/stat.h> |
19 # include <sys/types.h> | 19 # include <sys/types.h> |
20 #endif | 20 #endif |
21 | 21 |
22 #ifdef __WIN32 | 22 #ifdef TH_PLAT_WINDOWS |
23 # define SET_CONFIG_FILE "nnchat.txt" | 23 # define SET_CONFIG_FILE "nnchat.txt" |
24 # define SET_LOG_DIR "NNChat Log Files" | 24 # define SET_LOG_DIR "NNChat Log Files" |
25 # define SET_DIR_SEPARATOR '\\' | 25 # define SET_DIR_SEPARATOR '\\' |
26 #else | 26 #else |
27 # define SET_DIR_SEPARATOR '/' | 27 # define SET_DIR_SEPARATOR '/' |
928 } | 928 } |
929 | 929 |
930 | 930 |
931 int nn_open_uri(const char *uri) | 931 int nn_open_uri(const char *uri) |
932 { | 932 { |
933 #ifdef __WIN32 | 933 #ifdef TH_PLAT_WINDOWS |
934 HINSTANCE status; | 934 HINSTANCE status; |
935 | 935 |
936 status = ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNA); | 936 status = ShellExecute(NULL, "open", uri, NULL, NULL, SW_SHOWNA); |
937 if (status <= (HINSTANCE) 32) | 937 if (status <= (HINSTANCE) 32) |
938 { | 938 { |
1264 int nncmd_save_config(th_conn_t *conn, char *buf) | 1264 int nncmd_save_config(th_conn_t *conn, char *buf) |
1265 { | 1265 { |
1266 (void) conn; | 1266 (void) conn; |
1267 (void) buf; | 1267 (void) buf; |
1268 th_ioctx_t ctx; | 1268 th_ioctx_t ctx; |
1269 #ifndef __WIN32 | 1269 #ifndef TH_PLAT_WINDOWS |
1270 int cfgfd = -1; | 1270 int cfgfd = -1; |
1271 #endif | 1271 #endif |
1272 | 1272 |
1273 if (!th_ioctx_init(&ctx, setConfigFile, nn_ioctx_errfunc, nn_ioctx_msgfunc)) | 1273 if (!th_ioctx_init(&ctx, setConfigFile, nn_ioctx_errfunc, nn_ioctx_msgfunc)) |
1274 { | 1274 { |
1827 | 1827 |
1828 | 1828 |
1829 BOOL nn_log_open(nn_window_t *win) | 1829 BOOL nn_log_open(nn_window_t *win) |
1830 { | 1830 { |
1831 char *path = NULL, *plt; | 1831 char *path = NULL, *plt; |
1832 #ifndef __WIN32 | 1832 #ifndef TH_PLAT_WINDOWS |
1833 int logFd = -1; | 1833 int logFd = -1; |
1834 #endif | 1834 #endif |
1835 | 1835 |
1836 if (!optLogEnable || optLogPath == NULL) | 1836 if (!optLogEnable || optLogPath == NULL) |
1837 return FALSE; | 1837 return FALSE; |
1882 | 1882 |
1883 // Try to open the file for appending | 1883 // Try to open the file for appending |
1884 if (win->logFilename == NULL) | 1884 if (win->logFilename == NULL) |
1885 goto error; | 1885 goto error; |
1886 | 1886 |
1887 #ifdef __WIN32 | 1887 #ifdef TH_PLAT_WINDOWS |
1888 if ((win->logFile = fopen(win->logFilename, "a")) == NULL) | 1888 if ((win->logFile = fopen(win->logFilename, "a")) == NULL) |
1889 #else | 1889 #else |
1890 if ((logFd = open(win->logFilename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || | 1890 if ((logFd = open(win->logFilename, O_CREAT | O_APPEND | O_WRONLY, S_IRUSR | S_IWUSR)) == -1 || |
1891 (win->logFile = fdopen(logFd, "a")) == NULL) | 1891 (win->logFile = fdopen(logFd, "a")) == NULL) |
1892 #endif | 1892 #endif |
1906 th_free(path); | 1906 th_free(path); |
1907 th_free(win->logFilename); | 1907 th_free(win->logFilename); |
1908 win->logFilename = NULL; | 1908 win->logFilename = NULL; |
1909 if (win->logFile != NULL) | 1909 if (win->logFile != NULL) |
1910 fclose(win->logFile); | 1910 fclose(win->logFile); |
1911 #ifndef __WIN32 | 1911 #ifndef TH_PLAT_WINDOWS |
1912 else | 1912 else |
1913 if (logFd >= 0) | 1913 if (logFd >= 0) |
1914 close(logFd); | 1914 close(logFd); |
1915 #endif | 1915 #endif |
1916 return FALSE; | 1916 return FALSE; |
1935 } | 1935 } |
1936 | 1936 |
1937 | 1937 |
1938 BOOL nn_stat_path(const char *path, BOOL *isDirectory, BOOL *isWritable, BOOL *isReadable) | 1938 BOOL nn_stat_path(const char *path, BOOL *isDirectory, BOOL *isWritable, BOOL *isReadable) |
1939 { | 1939 { |
1940 #ifdef __WIN32 | 1940 #ifdef TH_PLAT_WINDOWS |
1941 DWORD attr = GetFileAttributes(path); | 1941 DWORD attr = GetFileAttributes(path); |
1942 | 1942 |
1943 *isDirectory = (attr & FILE_ATTRIBUTE_DIRECTORY) != 0; | 1943 *isDirectory = (attr & FILE_ATTRIBUTE_DIRECTORY) != 0; |
1944 *isWritable = (attr & FILE_ATTRIBUTE_READONLY) == 0; | 1944 *isWritable = (attr & FILE_ATTRIBUTE_READONLY) == 0; |
1945 *isReadable = TRUE; | 1945 *isReadable = TRUE; |
1983 if (exists && !isDir) | 1983 if (exists && !isDir) |
1984 goto error; | 1984 goto error; |
1985 | 1985 |
1986 if (!exists) | 1986 if (!exists) |
1987 { | 1987 { |
1988 #ifdef __WIN32 | 1988 #ifdef TH_PLAT_WINDOWS |
1989 if (!CreateDirectory(path, NULL)) | 1989 if (!CreateDirectory(path, NULL)) |
1990 goto error; | 1990 goto error; |
1991 #else | 1991 #else |
1992 if (mkdir(path, 0x1c9) < 0) | 1992 if (mkdir(path, 0x1c9) < 0) |
1993 goto error; | 1993 goto error; |
2096 | 2096 |
2097 th_cfg_add_section(&cfg, "logging", tmpcfg); | 2097 th_cfg_add_section(&cfg, "logging", tmpcfg); |
2098 | 2098 |
2099 // Get home directory path | 2099 // Get home directory path |
2100 { | 2100 { |
2101 #if defined(__WIN32) | 2101 #if defined(TH_PLAT_WINDOWS) |
2102 char tmpPath[MAX_PATH]; | 2102 char tmpPath[MAX_PATH]; |
2103 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) | 2103 if (SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, tmpPath) == S_OK) |
2104 setHomeDir = th_strdup(tmpPath); | 2104 setHomeDir = th_strdup(tmpPath); |
2105 | 2105 |
2106 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); | 2106 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); |
2162 goto err_exit; | 2162 goto err_exit; |
2163 } | 2163 } |
2164 else | 2164 else |
2165 if (!isWritable) | 2165 if (!isWritable) |
2166 { | 2166 { |
2167 #ifdef __WIN32 | 2167 #ifdef TH_PLAT_WINDOWS |
2168 if (!nn_mkdir_rec(optLogPath)) | 2168 if (!nn_mkdir_rec(optLogPath)) |
2169 { | 2169 { |
2170 THERR("Could not create log file directory '%s'.\n", | 2170 THERR("Could not create log file directory '%s'.\n", |
2171 optLogPath); | 2171 optLogPath); |
2172 goto err_exit; | 2172 goto err_exit; |
2433 for (index = 0; index <= SET_MAX_HISTORY; index++) | 2433 for (index = 0; index <= SET_MAX_HISTORY; index++) |
2434 nn_editbuf_free(editHistBuf[index]); | 2434 nn_editbuf_free(editHistBuf[index]); |
2435 | 2435 |
2436 nnwin_shutdown(); | 2436 nnwin_shutdown(); |
2437 | 2437 |
2438 #ifndef __WIN32 | 2438 #ifndef TH_PLAT_WINDOWS |
2439 if (errorMessages) | 2439 if (errorMessages) |
2440 THERR("%s", errorMessages); | 2440 THERR("%s", errorMessages); |
2441 #endif | 2441 #endif |
2442 | 2442 |
2443 th_free(optUserNameEnc); | 2443 th_free(optUserNameEnc); |