wrc: Store version and characteristics as simple integers.
[wine.git] / programs / fsutil / main.c
blob94151ae9b42f7ae53e2b8867d28fef310259dc72
1 /*
2 * Copyright 2016 Austin English
3 * Copyright 2016 Michael Müller
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <windows.h>
22 #include "wine/debug.h"
23 #include "resources.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(fsutil);
27 static void output_write(const WCHAR *str, DWORD wlen)
29 DWORD count, ret;
31 ret = WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), str, wlen, &count, NULL);
32 if (!ret)
34 DWORD len;
35 char *msgA;
37 /* On Windows WriteConsoleW() fails if the output is redirected. So fall
38 * back to WriteFile(), assuming the console encoding is still the right
39 * one in that case.
41 len = WideCharToMultiByte(CP_ACP, 0, str, wlen, NULL, 0, NULL, NULL);
42 msgA = HeapAlloc(GetProcessHeap(), 0, len * sizeof(char));
43 if (!msgA) return;
45 WideCharToMultiByte(CP_ACP, 0, str, wlen, msgA, len, NULL, NULL);
46 WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), msgA, len, &count, FALSE);
47 HeapFree(GetProcessHeap(), 0, msgA);
51 static int WINAPIV output_string(int msg, ...)
53 WCHAR out[8192];
54 va_list arguments;
55 int len;
57 va_start(arguments, msg);
58 len = FormatMessageW(FORMAT_MESSAGE_FROM_HMODULE, NULL, msg, 0, out, ARRAY_SIZE(out), &arguments);
59 va_end(arguments);
61 if (len == 0 && GetLastError() != NO_ERROR)
62 WINE_FIXME("Could not format string: le=%lu, msg=%d\n", GetLastError(), msg);
63 else
64 output_write(out, len);
66 return 0;
69 static BOOL output_error_string(DWORD error)
71 LPWSTR pBuffer;
72 if (FormatMessageW(FORMAT_MESSAGE_FROM_SYSTEM |
73 FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ALLOCATE_BUFFER,
74 NULL, error, 0, (LPWSTR)&pBuffer, 0, NULL))
76 output_write(pBuffer, lstrlenW(pBuffer));
77 LocalFree(pBuffer);
78 return TRUE;
80 return FALSE;
83 static int create_hardlink(int argc, WCHAR *argv[])
85 if (argc != 5)
87 output_string(STRING_HARDLINK_CREATE_USAGE);
88 return 1;
91 if (CreateHardLinkW(argv[3], argv[4], NULL))
92 return 0;
94 output_error_string(GetLastError());
95 return 1;
98 static int hardlink(int argc, WCHAR *argv[])
100 int ret = 0;
102 if (argc > 2)
104 if (!wcsicmp(argv[2], L"create"))
105 return create_hardlink(argc, argv);
106 else
108 FIXME("unsupported parameter %s\n", debugstr_w(argv[2]));
109 ret = 1;
113 output_string(STRING_HARDLINK_USAGE);
114 return ret;
117 int __cdecl wmain(int argc, WCHAR *argv[])
119 int i, ret = 0;
121 TRACE("Command line:");
122 for (i = 0; i < argc; i++)
123 TRACE(" %s", debugstr_w(argv[i]));
124 TRACE("\n");
126 if (argc > 1)
128 if (!wcsicmp(argv[1], L"hardlink"))
129 return hardlink(argc, argv);
130 else
132 FIXME("unsupported command %s\n", debugstr_w(argv[1]));
133 ret = 1;
137 output_string(STRING_USAGE);
138 return ret;