Damul Project/kxLibrary
                
              kxBuffLib::kxFile Class Source Code
                DURUMUL
                 2011. 10. 6. 13:46
              
              
            
            | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
 | /*
 * kxBuffLibrary : krkim's eXtended Intelligent & Sequencial Linear Buffer Library
 * PURPOSE : Intelligent increasing buffer with a big buffer data,add to sequencial data,
 * 	         string,list like MFC String or PtrArray on Non-MFC platforms(general C/C++).
 * 
 * Copyright(c) 2005-2010 Durumul.com ,Korea
 * Author  : KRKIM(kyung rae kim) 
 * yeamaec@hanafos.com (http://www.durumul.com, http://krkim.net)
 * 
 * Version : 1.0.4
 * This source is free to use as you like but leave this notice.
 * If you make any changes(bugfix,updating),please mail the new version to me.
 * 
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */
/*
  History:
    1.0.3  - 2007.11.27 <krkim> add operators to IBuff.
    1.0.2  - 2007.11    <krkim> Renew TCHAR and LPTSTR for UNICODE Compatible.
    1.0.1  - 2006.12.07 <krkim> Add resize at kxList.
    1.0.0  - not support decreasing buffer.
    Initial version 1.0 2005 12.15 KRKIM.
 */
#pragma once
#pragma warning (push)
#pragma warning(disable : 4996)
#ifndef KXFILE__H
#define KXFILE__H
#include <kxbuff.h>
namespace kxBuffLib{
class kxFile
{
public:
	FILE *m_fp;
	kxFile(){
		m_fp = 0;
	}
	kxFile(kxString file,kxString mode){
		m_fp = fopen(file,mode);
	}
	~kxFile(){
		if(m_fp) fclose(m_fp);
		m_fp = 0;
	}
	FILE *fp(){
		return m_fp;
	}
	bool IsOpened() { return m_fp != 0;}
	bool Close(){
		if(m_fp)
			fclose(m_fp);
		m_fp = 0;
	}
	kxFile& operator=(const kxFile& srcFile){ 
		Close();
		m_fp = srcFile.m_fp;
		return (*this); 
	}
	//
	// 밀리 초는 10^-3 초 입니다.마이크로는 10^-6초 나노초는 10^-9초 피코초는 10^-12초 입니다 10^-1 = 10분의 1초
	static INT64 ConvFileTime(FILETIME filetime)//10초당 (100나노초) 단위
	{
		INT64 i64;
		//FILETIME = 100나노초
		i64=(((INT64)filetime.dwHighDateTime) << 32) + filetime.dwLowDateTime;
		i64 = i64 / 100000000;//10초를 100나노초 단위로 환산
		return i64;
	}
	static INT64 ConvSystemTime(SYSTEMTIME systime)//10초 단위 100나노초단위로 변환
	{
		INT64 i64;
		FILETIME ft;//100나노초 단위
		//1초 = 1000000000 나노초
		//1초 = 10000000 (100나노초)
		//하루 = 86400 초 = 864000000000 (100나노초)
		//1분 = 60초
		systime.wMilliseconds = systime.wDayOfWeek = 0;
		SystemTimeToFileTime(&systime,&ft);
		i64=ConvFileTime(ft);
		return i64;
	}
	static bool FileExists(LPCTSTR szFile,INT64 *lwtime = NULL)
	{
		HANDLE flag32;
		WIN32_FIND_DATA read32={0,};//32bit porting routine..
		if((flag32 = FindFirstFile(szFile,&read32)) == INVALID_HANDLE_VALUE){
			if(lwtime)
				*lwtime = kxFile::ConvFileTime(read32.ftLastWriteTime);
			return false;
		}
		FindClose(flag32);
		return true;
	}
};
}
using namespace kxBuffLib;
#endif
#pragma warning (pop) | 
 kxFile.h
kxFile.h