[NET/USE]
[reactos.git] / reactos / base / applications / network / net / cmdUse.c
index 7ad5a1f..f0f405d 100644 (file)
@@ -9,8 +9,6 @@
 
 #include "net.h"
 
-#define COUNT_OF(a) (sizeof(a) / sizeof(a[0]))
-
 static
 DWORD
 EnumerateConnections(LPCWSTR Local)
@@ -65,6 +63,21 @@ EnumerateConnections(LPCWSTR Local)
     return 0;
 }
 
+static
+VOID
+PrintError(DWORD Status)
+{
+    LPWSTR Buffer;
+
+    ConResPrintf(StdErr, IDS_ERROR_SYSTEM_ERROR, Status);
+
+    if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, Status, 0, (LPWSTR)&Buffer, 0, NULL))
+    {
+        ConPrintf(StdErr, L"\n%s", Buffer);
+        LocalFree(Buffer);
+    }
+}
+
 INT
 cmdUse(
     INT argc,
@@ -75,7 +88,11 @@ cmdUse(
     if (argc == 2)
     {
         Status = EnumerateConnections(NULL);
-        ConPrintf(StdOut, L"Status: %lu\n", Status);
+        if (Status == NO_ERROR)
+            ConResPrintf(StdOut, IDS_ERROR_NO_ERROR);
+        else
+            PrintError(Status);
+
         return 0;
     }
     else if (argc == 3)
@@ -94,7 +111,11 @@ cmdUse(
         }
 
         Status = EnumerateConnections(argv[2]);
-        ConPrintf(StdOut, L"Status: %lu\n", Status);
+        if (Status == NO_ERROR)
+            ConResPrintf(StdOut, IDS_ERROR_NO_ERROR);
+        else
+            PrintError(Status);
+
         return 0;
     }
 
@@ -102,7 +123,6 @@ cmdUse(
     if (Len != 1 && Len != 2)
     {
         ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"DeviceName");
-        ConPrintf(StdOut, L"Len: %lu\n", Len);
         return 1;
     }
 
@@ -133,7 +153,7 @@ cmdUse(
         BOOL Persist = FALSE;
         NETRESOURCE lpNet;
         WCHAR Access[256];
-        DWORD OutFlags = 0, Size = COUNT_OF(Access);
+        DWORD OutFlags = 0, Size = ARRAYSIZE(Access);
 
         Len = wcslen(argv[3]);
         if (Len < 4)
@@ -192,7 +212,9 @@ cmdUse(
 
         Status = WNetUseConnection(NULL, &lpNet, NULL, NULL, CONNECT_REDIRECT | (Persist ? CONNECT_UPDATE_PROFILE : 0), Access, &Size, &OutFlags);
         if (argv[2][0] == L'*' && Status == NO_ERROR && OutFlags == CONNECT_LOCALDRIVE)
-            ConPrintf(StdOut, L"%s is now connected to %s\n", argv[3], Access);
+            ConResPrintf(StdOut, IDS_USE_NOW_CONNECTED, argv[3], Access);
+        else if (Status != NO_ERROR)
+            PrintError(Status);
 
         return Status;
     }