/*
 * ************************************************************************************************************
 * Author: Marcin Załęczny
 * Copyright (C)2010 Marcin Załęczny <mzaleczny@hotmail.com>
 * License: The GNU Lesser General Public License, version 3.0 (LGPLv3)
 * Library Name: mzstd
 * Version: 1.07
 * First release date:   2010-11-08
 * Current release date: 2011-03-04
 *
 *
 * This file is part of mzstd library
 * 
 * mzstd library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * mzstd library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************************************************
 */

#ifndef __MZSTD_FILE_UTILS_H__
#define __MZSTD_FILE_UTILS_H__

#include "mzstdCommon.h"
#include "mzString.h"

class CStringList;
class CLogger;
extern CLogger* logger;

DECLSPEC_MZSTD DWORD WINAPI GetFileSize(CString fname);
DECLSPEC_MZSTD CString WINAPI ReadFile(CString fname, LONG encoding = 0);
DECLSPEC_MZSTD LONG WINAPI ReadBinaryFile(CString fname, BYTE* buffer);
DECLSPEC_MZSTD DWORD WINAPI AppendToFile(HANDLE fh, WCHAR* content, LONG encoding = ENC_UTF8);
DECLSPEC_MZSTD DWORD WINAPI AppendToFile(HANDLE fh, BYTE* data, ULONG datasize);
DECLSPEC_MZSTD BOOL WINAPI WriteToFile(CString fname, CString content, LONG encoding = ENC_UTF8, DWORD creationDisposition = CREATE_ALWAYS);
DECLSPEC_MZSTD BOOL WINAPI WriteFile(CString fname, CString content, LONG encoding = ENC_UTF8);
DECLSPEC_MZSTD BOOL WINAPI AppendToFile(CString fname, CString content, LONG encoding = ENC_UTF8);
DECLSPEC_MZSTD BOOL WINAPI WriteFile(CString fname, CStringList *lst, LONG encoding = ENC_UTF8);
DECLSPEC_MZSTD BOOL WINAPI WriteFile(CString fname, BYTE* data, DWORD dataLength);
DECLSPEC_MZSTD BOOL WINAPI DirectoryExists(CString dirname);
DECLSPEC_MZSTD BOOL WINAPI FileExists(CString fname);
DECLSPEC_MZSTD CString WINAPI GetCurrentDirectory();
DECLSPEC_MZSTD CStringList* WINAPI GetDirectoryContent(CString dir);
DECLSPEC_MZSTD CStringList* WINAPI GetDirectoryDirs(CString dir);
DECLSPEC_MZSTD BOOL WINAPI CreateDirectory(CString dir, BOOL createAll = FALSE);
// Warning!!!
// Function below removes recursively all directory without prompting. If read-only or system files encounters
// then removes these attributes and deletes this files. Cannot delete files if opened by another app or
// directories that are in use.
DECLSPEC_MZSTD BOOL WINAPI DeleteDirectory(CString dir);
// W poniższej funkcji rozszerzenie podajemy bez kropki
DECLSPEC_MZSTD CStringList* WINAPI GetDirectoryFiles(CString dir, CString ext = L"");
// Returns path extension without '.' (string after last '.')
DECLSPEC_MZSTD CString WINAPI GetExt(CString path);
// Returns only last path part ex. only filename (with extension) or last directory.
DECLSPEC_MZSTD CString WINAPI GetPathname(CString path);
// Returns only last path part ex. only filename or last directory without specified extension.
DECLSPEC_MZSTD CString WINAPI GetPathname(CString path, CString rtrimExt);
// Returns only last path part ex. only filename or last directory without any extension.
DECLSPEC_MZSTD CString WINAPI GetPathnameNoExt(CString path);
DECLSPEC_MZSTD BOOL WINAPI PathEndsWithPathSeparator(CString& path);
DECLSPEC_MZSTD BOOL WINAPI PathStartsWithPathSeparator(CString& path);
// adds extra path part to the specified path. If path not ends with PathSeparator, then the PathSeparator
// is inserted.
DECLSPEC_MZSTD VOID WINAPI AddPathPart(CString& path, CString partPathname);
// Splits path into array of directories. No matter if path exist.
DECLSPEC_MZSTD CStringList* WINAPI GetPathnameParts(CString path);
DECLSPEC_MZSTD VOID WINAPI TruncateEndingPathSeparator(CString& path);
DECLSPEC_MZSTD VOID WINAPI TruncateStartingPathSeparator(CString& path);
DECLSPEC_MZSTD VOID WINAPI TrimPathSeparators(CString& path);
// Returns full directory name of the path. If path is the file then full parent directory is returned. Else
// RealPath(path) is returned.
DECLSPEC_MZSTD CString WINAPI GetBasename(CString path);
// Returns full parent directory name of the path. If path is the file then full parent directory is returned.
// Else RealPath('path\\..') is returned.
DECLSPEC_MZSTD CString WINAPI GetParentDir(CString path);
// if path is not a full path ex. 'c:\test.txt' but a partial path ex. 'test.txt' or '..\\..\\dir\\test.txt' then
// returned value is: GetCurrentDirectory() + parse_and_apply('..') + if_required(\\) + path,
// else path is returned
DECLSPEC_MZSTD CString WINAPI RealPath(CString path);
DECLSPEC_MZSTD CString WINAPI GetWindowsDirectory();
DECLSPEC_MZSTD CString WINAPI GetSystemDirectory();

#endif
