Improve swedish translations and add new translations to swedish.
[reactos.git] / base / applications / mscutils / servman / export.c
1 /*
2 * PROJECT: ReactOS Services
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/mscutils/servman/export.c
5 * PURPOSE: Save services to a file
6 * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
7 *
8 */
9
10 #include "precomp.h"
11
12 #include <cderr.h>
13
14 static DWORD
15 GetTextFromListView(PMAIN_WND_INFO Info,
16 LPWSTR Text,
17 INT row,
18 INT col)
19 {
20 LVITEM item;
21 DWORD NumChars;
22
23 ZeroMemory(&item, sizeof(item));
24 item.mask = LVIF_TEXT;
25 item.iSubItem = col;
26 item.pszText = Text;
27 item.cchTextMax = 500;
28 NumChars = (INT)SendMessageW(Info->hListView,
29 LVM_GETITEMTEXTW,
30 row,
31 (LPARAM)&item);
32 return NumChars;
33 }
34
35 static BOOL
36 SaveServicesToFile(PMAIN_WND_INFO Info,
37 LPCWSTR pszFileName)
38 {
39 HANDLE hFile;
40 BOOL bSuccess = FALSE;
41
42 hFile = CreateFileW(pszFileName,
43 GENERIC_WRITE,
44 0,
45 NULL,
46 CREATE_ALWAYS,
47 FILE_ATTRIBUTE_NORMAL,
48 NULL);
49
50 if(hFile != INVALID_HANDLE_VALUE)
51 {
52 WCHAR LVText[500];
53 WCHAR newl[2] = {L'\r', L'\n'};
54 WCHAR tab = L'\t';
55 DWORD dwTextLength, dwWritten;
56 INT NumListedServ = 0;
57 INT i, k;
58
59 NumListedServ = ListView_GetItemCount(Info->hListView);
60
61 for (i=0; i < NumListedServ; i++)
62 {
63 for (k=0; k<5; k++)
64 {
65 dwTextLength = GetTextFromListView(Info,
66 LVText,
67 i,
68 k);
69 if (dwTextLength != 0)
70 {
71 WriteFile(hFile,
72 LVText,
73 sizeof(WCHAR) * dwTextLength,
74 &dwWritten,
75 NULL);
76
77 WriteFile(hFile,
78 &tab,
79 sizeof(WCHAR),
80 &dwWritten,
81 NULL);
82 }
83 }
84 WriteFile(hFile,
85 newl,
86 sizeof(newl),
87 &dwWritten,
88 NULL);
89 }
90
91 CloseHandle(hFile);
92 bSuccess = TRUE;
93 }
94
95 return bSuccess;
96 }
97
98 VOID ExportFile(PMAIN_WND_INFO Info)
99 {
100 OPENFILENAMEW ofn;
101 WCHAR szFileName[MAX_PATH];
102
103 ZeroMemory(&ofn, sizeof(ofn));
104 szFileName[0] = UNICODE_NULL;
105
106 ofn.lStructSize = sizeof(OPENFILENAME);
107 ofn.hwndOwner = Info->hMainWnd;
108 ofn.lpstrFilter = L"Text (Tab Delimited)(*.txt)\0*.txt\0Text (Comma Delimited)(*.csv)\0*.csv\0";
109 ofn.lpstrFile = szFileName;
110 ofn.nMaxFile = MAX_PATH;
111 ofn.lpstrDefExt = L"txt";
112 ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
113
114 if(GetSaveFileName(&ofn))
115 {
116 if (SaveServicesToFile(Info, szFileName))
117 return;
118 }
119
120 if (CommDlgExtendedError() != CDERR_GENERALCODES)
121 MessageBoxW(NULL, L"Export to file failed", NULL, 0);
122 }