2006-11-08 11:47:44 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS Services
|
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
2015-09-09 13:13:35 +00:00
|
|
|
* FILE: base/applications/mscutils/servman/export.c
|
2006-11-08 11:47:44 +00:00
|
|
|
* PURPOSE: Save services to a file
|
|
|
|
* COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precomp.h"
|
|
|
|
|
2016-11-02 18:55:51 +00:00
|
|
|
#include <cderr.h>
|
2014-01-07 16:27:17 +00:00
|
|
|
|
2006-11-08 11:47:44 +00:00
|
|
|
static DWORD
|
|
|
|
GetTextFromListView(PMAIN_WND_INFO Info,
|
2015-04-08 17:30:38 +00:00
|
|
|
LPWSTR Text,
|
2006-11-08 11:47:44 +00:00
|
|
|
INT row,
|
|
|
|
INT col)
|
|
|
|
{
|
|
|
|
LVITEM item;
|
|
|
|
DWORD NumChars;
|
|
|
|
|
|
|
|
ZeroMemory(&item, sizeof(item));
|
|
|
|
item.mask = LVIF_TEXT;
|
|
|
|
item.iSubItem = col;
|
|
|
|
item.pszText = Text;
|
|
|
|
item.cchTextMax = 500;
|
2015-04-08 17:30:38 +00:00
|
|
|
NumChars = (INT)SendMessageW(Info->hListView,
|
|
|
|
LVM_GETITEMTEXTW,
|
|
|
|
row,
|
|
|
|
(LPARAM)&item);
|
2006-11-08 11:47:44 +00:00
|
|
|
return NumChars;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL
|
|
|
|
SaveServicesToFile(PMAIN_WND_INFO Info,
|
2015-04-08 17:30:38 +00:00
|
|
|
LPCWSTR pszFileName)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
2007-08-24 18:27:12 +00:00
|
|
|
HANDLE hFile;
|
|
|
|
BOOL bSuccess = FALSE;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2015-04-08 17:30:38 +00:00
|
|
|
hFile = CreateFileW(pszFileName,
|
2006-11-08 11:47:44 +00:00
|
|
|
GENERIC_WRITE,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
CREATE_ALWAYS,
|
|
|
|
FILE_ATTRIBUTE_NORMAL,
|
|
|
|
NULL);
|
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
if(hFile != INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2015-04-08 17:30:38 +00:00
|
|
|
WCHAR LVText[500];
|
|
|
|
WCHAR newl[2] = {L'\r', L'\n'};
|
|
|
|
WCHAR tab = L'\t';
|
2007-08-24 18:27:12 +00:00
|
|
|
DWORD dwTextLength, dwWritten;
|
|
|
|
INT NumListedServ = 0;
|
|
|
|
INT i, k;
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
NumListedServ = ListView_GetItemCount(Info->hListView);
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
for (i=0; i < NumListedServ; i++)
|
|
|
|
{
|
|
|
|
for (k=0; k<5; k++)
|
|
|
|
{
|
2006-11-08 11:47:44 +00:00
|
|
|
dwTextLength = GetTextFromListView(Info,
|
|
|
|
LVText,
|
|
|
|
i,
|
|
|
|
k);
|
2014-10-22 19:28:33 +00:00
|
|
|
if (dwTextLength != 0)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
WriteFile(hFile,
|
|
|
|
LVText,
|
2015-04-08 17:30:38 +00:00
|
|
|
sizeof(WCHAR) * dwTextLength,
|
2006-11-08 11:47:44 +00:00
|
|
|
&dwWritten,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
WriteFile(hFile,
|
|
|
|
&tab,
|
2015-04-08 17:30:38 +00:00
|
|
|
sizeof(WCHAR),
|
2006-11-08 11:47:44 +00:00
|
|
|
&dwWritten,
|
|
|
|
NULL);
|
|
|
|
}
|
2007-08-24 18:27:12 +00:00
|
|
|
}
|
|
|
|
WriteFile(hFile,
|
2014-10-21 22:58:23 +00:00
|
|
|
newl,
|
|
|
|
sizeof(newl),
|
2006-11-08 11:47:44 +00:00
|
|
|
&dwWritten,
|
|
|
|
NULL);
|
2007-08-24 18:27:12 +00:00
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
CloseHandle(hFile);
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
return bSuccess;
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID ExportFile(PMAIN_WND_INFO Info)
|
|
|
|
{
|
2015-04-08 17:30:38 +00:00
|
|
|
OPENFILENAMEW ofn;
|
|
|
|
WCHAR szFileName[MAX_PATH];
|
2007-08-24 18:27:12 +00:00
|
|
|
|
|
|
|
ZeroMemory(&ofn, sizeof(ofn));
|
2015-04-08 17:30:38 +00:00
|
|
|
szFileName[0] = UNICODE_NULL;
|
2007-08-24 18:27:12 +00:00
|
|
|
|
|
|
|
ofn.lStructSize = sizeof(OPENFILENAME);
|
|
|
|
ofn.hwndOwner = Info->hMainWnd;
|
2015-04-08 17:30:38 +00:00
|
|
|
ofn.lpstrFilter = L"Text (Tab Delimited)(*.txt)\0*.txt\0Text (Comma Delimited)(*.csv)\0*.csv\0";
|
2007-08-24 18:27:12 +00:00
|
|
|
ofn.lpstrFile = szFileName;
|
|
|
|
ofn.nMaxFile = MAX_PATH;
|
2015-04-08 17:30:38 +00:00
|
|
|
ofn.lpstrDefExt = L"txt";
|
2007-08-24 18:27:12 +00:00
|
|
|
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
|
|
|
|
|
|
|
|
if(GetSaveFileName(&ofn))
|
|
|
|
{
|
|
|
|
if (SaveServicesToFile(Info, szFileName))
|
2006-11-08 11:47:44 +00:00
|
|
|
return;
|
2007-08-24 18:27:12 +00:00
|
|
|
}
|
2006-11-08 11:47:44 +00:00
|
|
|
|
2007-08-24 18:27:12 +00:00
|
|
|
if (CommDlgExtendedError() != CDERR_GENERALCODES)
|
2015-04-08 17:30:38 +00:00
|
|
|
MessageBoxW(NULL, L"Export to file failed", NULL, 0);
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|