forked from sunnyprogrammer77/CommonFunc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonFunc.cpp
More file actions
72 lines (69 loc) · 1.48 KB
/
CommonFunc.cpp
File metadata and controls
72 lines (69 loc) · 1.48 KB
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
#include "CommonFunc.h"
#include <string.h>
#include<fstream>
#include <io.h>
#include "shlwapi.h"
#pragma comment(lib,"shlwapi.lib")
CommonFunc::CommonFunc()
{
}
CommonFunc::~CommonFunc()
{
}
//-------------------计算文件的长度并返回大小------------------------//
size_t CommonFunc::GetFileSize(const char * filename)
{
std::ifstream ifs(filename);
if (!ifs)
{
printf("%s文件打开失败(计算文件长度)",filename);
return 0;
}
ifs.seekg(0, std::ios::end);
size_t size = ifs.tellg();
ifs.close();
return size;
}
//------------------获得音频文件的类型后期可以扩展更多的类型----------------------//
AudioType CommonFunc::GetAudioType(const char* filename)
{
if (filename == NULL)
return UNKNOWN_AUDIO;
size_t len = strlen(filename);
if (filename[len - 1] == '3')
return MP3_AUDIO;
if (filename[len - 1] == 'v' || filename[len - 1] == 'V')
return WAV_AUDIO;
if (filename[len - 1] == 'm' || filename[len - 1] == 'M')
return PCM_AUDIO;
return UNKNOWN_AUDIO;
}
bool CommonFunc::CheckFolderExit(char* folderName, bool flag = false)
{
if (_access(folderName, 0) == -1)
{
if (flag)
CreateDirectory(folderName, NULL);
else
return false;
}
return true;
}
bool CommonFunc::CheckFileExit(char* fileName, bool flag = false)
{
if (_access(fileName, 0) == -1)
{
if (flag)
{
if (!fopen(fileName, "ab+"))
{
printf("文件创建失败!");
return false;
}
else
return true;
}
else
return false;
}
}