调试绑定文件夹的功能,可以调整输出文件的命名方式
This commit is contained in:
parent
ba76ed3c09
commit
a8bed1c462
Binary file not shown.
|
@ -147,6 +147,8 @@ namespace ver_2
|
|||
|
||||
m_bindFolder.clear();
|
||||
m_bindNameMode.clear();
|
||||
m_bindNameWidth = 0;
|
||||
m_bindNameBase = 0;
|
||||
}
|
||||
|
||||
ManagerV2::~ManagerV2()
|
||||
|
@ -1131,7 +1133,7 @@ namespace ver_2
|
|||
m_currBatchId = batchId;
|
||||
if (!m_bindFolder.empty())
|
||||
{
|
||||
ClearBindFolderImageList();
|
||||
ClearBindFolder();
|
||||
UpdateBindFolder();
|
||||
}
|
||||
}
|
||||
|
@ -1190,7 +1192,7 @@ namespace ver_2
|
|||
m_currBatchId = batchId;
|
||||
if (!m_bindFolder.empty())
|
||||
{
|
||||
ClearBindFolderImageList();
|
||||
ClearBindFolder();
|
||||
UpdateBindFolder();
|
||||
}
|
||||
|
||||
|
@ -1236,12 +1238,12 @@ namespace ver_2
|
|||
return 0;
|
||||
}
|
||||
|
||||
int ManagerV2::BindFolder(const std::string& folder, const std::string& nameMode, std::string& errInfo)
|
||||
int ManagerV2::BindFolder(const std::string& folder, const std::string& nameMode, int nameWidth, int nameBase, std::string& errInfo)
|
||||
{
|
||||
errInfo = "错误";
|
||||
if (folder.empty())
|
||||
return -1;
|
||||
if ("index" != nameMode)
|
||||
if ("order" != nameMode || nameWidth <= 0 || nameBase < 0)
|
||||
return -1;
|
||||
|
||||
// 需要保证文件夹为空??
|
||||
|
@ -1255,8 +1257,10 @@ namespace ver_2
|
|||
HGBase_StandardiseFileName(m_bindFolder.c_str(), stdBindFolder, 256);
|
||||
m_bindFolder = stdBindFolder;
|
||||
m_bindNameMode = nameMode;
|
||||
m_bindNameWidth = nameWidth;
|
||||
m_bindNameBase = nameBase;
|
||||
|
||||
ClearBindFolderImageList();
|
||||
ClearBindFolder();
|
||||
UpdateBindFolder();
|
||||
|
||||
errInfo.clear();
|
||||
|
@ -1272,6 +1276,8 @@ namespace ver_2
|
|||
|
||||
m_bindFolder.clear();
|
||||
m_bindNameMode.clear();
|
||||
m_bindNameWidth = 0;
|
||||
m_bindNameBase = 0;
|
||||
errInfo.clear();
|
||||
return 0;
|
||||
}
|
||||
|
@ -1779,6 +1785,9 @@ namespace ver_2
|
|||
if (NULL == m_sqlite)
|
||||
return -1;
|
||||
|
||||
std::vector<BatchTableInfo> tables;
|
||||
GetBatchTableInfo(tables);
|
||||
|
||||
char sql[256];
|
||||
sprintf(sql, "delete from 'table_%s'", m_currBatchId.c_str());
|
||||
int ret = sqlite3_exec(m_sqlite, sql, NULL, NULL, NULL);
|
||||
|
@ -1786,7 +1795,7 @@ namespace ver_2
|
|||
|
||||
if (!m_bindFolder.empty())
|
||||
{
|
||||
ClearBindFolderImageList();
|
||||
ClearBindFolderImageList(tables);
|
||||
}
|
||||
|
||||
errInfo.clear();
|
||||
|
@ -2055,13 +2064,7 @@ namespace ver_2
|
|||
|
||||
if (!m_bindFolder.empty())
|
||||
{
|
||||
for (int i = 0; i < (int)tables.size(); ++i)
|
||||
{
|
||||
char fileName[256];
|
||||
sprintf(fileName, "%s%d.%s", m_bindFolder.c_str(), tables[i].idx, tables[i].format.c_str());
|
||||
HGBase_DeleteFile(fileName);
|
||||
}
|
||||
|
||||
ClearBindFolderImageList(tables);
|
||||
UpdateBindFolder();
|
||||
}
|
||||
|
||||
|
@ -2157,13 +2160,7 @@ namespace ver_2
|
|||
|
||||
if (!m_bindFolder.empty())
|
||||
{
|
||||
for (int i = 0; i < (int)tables.size(); ++i)
|
||||
{
|
||||
char fileName[256];
|
||||
sprintf(fileName, "%s%d.%s", m_bindFolder.c_str(), tables[i].idx, tables[i].format.c_str());
|
||||
HGBase_DeleteFile(fileName);
|
||||
}
|
||||
|
||||
ClearBindFolderImageList(tables);
|
||||
UpdateBindFolder();
|
||||
}
|
||||
|
||||
|
@ -3424,6 +3421,32 @@ namespace ver_2
|
|||
std::sort(tables.begin(), tables.end(), BatchTableSort);
|
||||
}
|
||||
|
||||
void ManagerV2::ClearBindFolder()
|
||||
{
|
||||
assert(!m_bindFolder.empty());
|
||||
|
||||
char szFind[MAX_PATH];
|
||||
sprintf(szFind, "%s*.*", m_bindFolder.c_str());
|
||||
|
||||
WIN32_FIND_DATAA FindFileData;
|
||||
HANDLE hFind = FindFirstFileA(szFind, &FindFileData);
|
||||
if (INVALID_HANDLE_VALUE == hFind)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
if (0 == (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
char fileName[MAX_PATH];
|
||||
sprintf(fileName, "%s%s", m_bindFolder.c_str(), FindFileData.cFileName);
|
||||
HGBase_DeleteFile(fileName);
|
||||
}
|
||||
|
||||
} while (FindNextFileA(hFind, &FindFileData));
|
||||
|
||||
FindClose(hFind);
|
||||
}
|
||||
|
||||
void ManagerV2::UpdateBindFolder()
|
||||
{
|
||||
assert(!m_bindFolder.empty());
|
||||
|
@ -3445,8 +3468,10 @@ namespace ver_2
|
|||
const void* imgData = sqlite3_column_blob(stmt, 4);
|
||||
int imgSize = sqlite3_column_bytes(stmt, 4);
|
||||
|
||||
char fmt[24];
|
||||
sprintf(fmt, "%%s%%0%dd.%%s", m_bindNameWidth);
|
||||
char imagePath[256];
|
||||
sprintf(imagePath, "%s%d.%s", m_bindFolder.c_str(), idx, imgFmt.c_str());
|
||||
sprintf(imagePath, fmt, m_bindFolder.c_str(), m_bindNameBase + idx, imgFmt.c_str());
|
||||
HGBase_CreateDir(m_bindFolder.c_str());
|
||||
SaveToFile((const HGByte*)imgData, imgSize, imagePath);
|
||||
|
||||
|
@ -3462,20 +3487,23 @@ namespace ver_2
|
|||
{
|
||||
assert(!m_bindFolder.empty());
|
||||
|
||||
char fmt[24];
|
||||
sprintf(fmt, "%%s%%0%dd.%%s", m_bindNameWidth);
|
||||
|
||||
for (int i = (int)tables.size() - 1; i >= 0; --i)
|
||||
{
|
||||
if (tables[i].idx >= insertPos)
|
||||
{
|
||||
char fileName[256];
|
||||
sprintf(fileName, "%s%d.%s", m_bindFolder.c_str(), tables[i].idx, tables[i].format.c_str());
|
||||
sprintf(fileName, fmt, m_bindFolder.c_str(), m_bindNameBase + tables[i].idx, tables[i].format.c_str());
|
||||
char destName[256];
|
||||
sprintf(destName, "%s%d.%s", m_bindFolder.c_str(), tables[i].idx + 1, tables[i].format.c_str());
|
||||
sprintf(destName, fmt, m_bindFolder.c_str(), m_bindNameBase + tables[i].idx + 1, tables[i].format.c_str());
|
||||
MoveFileA(fileName, destName);
|
||||
}
|
||||
}
|
||||
|
||||
char fileName[256];
|
||||
sprintf(fileName, "%s%d.%s", m_bindFolder.c_str(), insertPos, imgFmt.c_str());
|
||||
sprintf(fileName, fmt, m_bindFolder.c_str(), m_bindNameBase + insertPos, imgFmt.c_str());
|
||||
SaveToFile(imgData, imgSize, fileName);
|
||||
}
|
||||
|
||||
|
@ -3484,6 +3512,9 @@ namespace ver_2
|
|||
{
|
||||
assert(!m_bindFolder.empty());
|
||||
|
||||
char fmt[24];
|
||||
sprintf(fmt, "%%s%%0%dd.%%s", m_bindNameWidth);
|
||||
|
||||
std::string oldFormat;
|
||||
for (int i = 0; i < (int)tables.size(); ++i)
|
||||
{
|
||||
|
@ -3495,11 +3526,11 @@ namespace ver_2
|
|||
}
|
||||
|
||||
char oldFileName[256];
|
||||
sprintf(oldFileName, "%s%d.%s", m_bindFolder.c_str(), imageIndex, oldFormat.c_str());
|
||||
sprintf(oldFileName, fmt, m_bindFolder.c_str(), m_bindNameBase + imageIndex, oldFormat.c_str());
|
||||
HGBase_DeleteFile(oldFileName);
|
||||
|
||||
char fileName[256];
|
||||
sprintf(fileName, "%s%d.%s", m_bindFolder.c_str(), imageIndex, imgFmt.c_str());
|
||||
sprintf(fileName, fmt, m_bindFolder.c_str(), m_bindNameBase + imageIndex, imgFmt.c_str());
|
||||
SaveToFile(imgData, imgSize, fileName);
|
||||
}
|
||||
|
||||
|
@ -3507,6 +3538,9 @@ namespace ver_2
|
|||
{
|
||||
assert(!m_bindFolder.empty());
|
||||
|
||||
char fmt[24];
|
||||
sprintf(fmt, "%%s%%0%dd.%%s", m_bindNameWidth);
|
||||
|
||||
for (int i = 0; i < (int)imageIndexList.size(); ++i)
|
||||
{
|
||||
for (int j = 0; j < (int)tables.size(); ++j)
|
||||
|
@ -3514,7 +3548,7 @@ namespace ver_2
|
|||
if (tables[j].idx == imageIndexList[i])
|
||||
{
|
||||
char fileName[256];
|
||||
sprintf(fileName, "%s%d.%s", m_bindFolder.c_str(), tables[j].idx, tables[j].format.c_str());
|
||||
sprintf(fileName, fmt, m_bindFolder.c_str(), m_bindNameBase + tables[j].idx, tables[j].format.c_str());
|
||||
HGBase_DeleteFile(fileName);
|
||||
break;
|
||||
}
|
||||
|
@ -3543,9 +3577,9 @@ namespace ver_2
|
|||
if (value > 0)
|
||||
{
|
||||
char fileName[256];
|
||||
sprintf(fileName, "%s%d.%s", m_bindFolder.c_str(), tables[i].idx, tables[i].format.c_str());
|
||||
sprintf(fileName, fmt, m_bindFolder.c_str(), m_bindNameBase + tables[i].idx, tables[i].format.c_str());
|
||||
char destName[256];
|
||||
sprintf(destName, "%s%d.%s", m_bindFolder.c_str(), tables[i].idx - value, tables[i].format.c_str());
|
||||
sprintf(destName, fmt, m_bindFolder.c_str(), m_bindNameBase + tables[i].idx - value, tables[i].format.c_str());
|
||||
MoveFileA(fileName, destName);
|
||||
}
|
||||
}
|
||||
|
@ -3556,6 +3590,9 @@ namespace ver_2
|
|||
{
|
||||
assert(!m_bindFolder.empty());
|
||||
|
||||
char fmt[24];
|
||||
sprintf(fmt, "%%s%%0%dd.%%s", m_bindNameWidth);
|
||||
|
||||
std::string format1, format2;
|
||||
|
||||
for (int i = 0; i < (int)tables.size(); ++i)
|
||||
|
@ -3567,46 +3604,35 @@ namespace ver_2
|
|||
}
|
||||
|
||||
char fileName1[256];
|
||||
sprintf(fileName1, "%s%d.%s", m_bindFolder.c_str(), imageIndex1, format1.c_str());
|
||||
sprintf(fileName1, fmt, m_bindFolder.c_str(), m_bindNameBase + imageIndex1, format1.c_str());
|
||||
char TmpFileName[256];
|
||||
sprintf(TmpFileName, "%sTemp", m_bindFolder.c_str());
|
||||
MoveFileA(fileName1, TmpFileName);
|
||||
|
||||
char fileName2[256];
|
||||
sprintf(fileName2, "%s%d.%s", m_bindFolder.c_str(), imageIndex2, format2.c_str());
|
||||
sprintf(fileName2, fmt, m_bindFolder.c_str(), m_bindNameBase + imageIndex2, format2.c_str());
|
||||
char fileName2Dest[256];
|
||||
sprintf(fileName2Dest, "%s%d.%s", m_bindFolder.c_str(), imageIndex1, format2.c_str());
|
||||
sprintf(fileName2Dest, fmt, m_bindFolder.c_str(), m_bindNameBase + imageIndex1, format2.c_str());
|
||||
MoveFileA(fileName2, fileName2Dest);
|
||||
|
||||
char fileName1Dest[256];
|
||||
sprintf(fileName1Dest, "%s%d.%s", m_bindFolder.c_str(), imageIndex2, format1.c_str());
|
||||
sprintf(fileName1Dest, fmt, m_bindFolder.c_str(), m_bindNameBase + imageIndex2, format1.c_str());
|
||||
MoveFileA(TmpFileName, fileName1Dest);
|
||||
}
|
||||
|
||||
void ManagerV2::ClearBindFolderImageList()
|
||||
void ManagerV2::ClearBindFolderImageList(const std::vector<BatchTableInfo>& tables)
|
||||
{
|
||||
assert(!m_bindFolder.empty());
|
||||
|
||||
char szFind[MAX_PATH];
|
||||
sprintf(szFind, "%s*.*", m_bindFolder.c_str());
|
||||
char fmt[24];
|
||||
sprintf(fmt, "%%s%%0%dd.%%s", m_bindNameWidth);
|
||||
|
||||
WIN32_FIND_DATAA FindFileData;
|
||||
HANDLE hFind = FindFirstFileA(szFind, &FindFileData);
|
||||
if (INVALID_HANDLE_VALUE == hFind)
|
||||
return;
|
||||
|
||||
do
|
||||
for (int i = 0; i < (int)tables.size(); ++i)
|
||||
{
|
||||
if (0 == (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
|
||||
{
|
||||
char fileName[MAX_PATH];
|
||||
sprintf(fileName, "%s%s", m_bindFolder.c_str(), FindFileData.cFileName);
|
||||
HGBase_DeleteFile(fileName);
|
||||
}
|
||||
|
||||
} while (FindNextFileA(hFind, &FindFileData));
|
||||
|
||||
FindClose(hFind);
|
||||
char fileName[256];
|
||||
sprintf(fileName, fmt, m_bindFolder.c_str(), m_bindNameBase + tables[i].idx, tables[i].format.c_str());
|
||||
HGBase_DeleteFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
int ManagerV2::sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param)
|
||||
|
|
|
@ -270,7 +270,7 @@ namespace ver_2
|
|||
// 修改批次号
|
||||
int ModifyBatchId(const std::string& batchId, const std::string& newBatchId, std::string& errInfo);
|
||||
// 绑定文件夹
|
||||
int BindFolder(const std::string &folder, const std::string &nameMode, std::string& errInfo);
|
||||
int BindFolder(const std::string &folder, const std::string &nameMode, int nameWidth, int nameBase, std::string& errInfo);
|
||||
// 停止绑定文件夹
|
||||
int StopBindFolder(std::string& errInfo);
|
||||
// 加载图像缩略图列表
|
||||
|
@ -350,6 +350,7 @@ namespace ver_2
|
|||
static bool SaveToBase64(const HGByte* data, HGUInt size, std::string& base64);
|
||||
static bool SaveToFile(const HGByte* data, HGUInt size, const std::string &filePath);
|
||||
void GetBatchTableInfo(std::vector<BatchTableInfo>& tables);
|
||||
void ClearBindFolder();
|
||||
void UpdateBindFolder();
|
||||
void InsertBindFolderImage(const std::vector<BatchTableInfo>& tables, int insertPos, const std::string imgFmt,
|
||||
const HGByte *imgData, HGUInt imgSize);
|
||||
|
@ -357,7 +358,7 @@ namespace ver_2
|
|||
const HGByte* imgData, HGUInt imgSize);
|
||||
void DeleteBindFolderImage(const std::vector<BatchTableInfo>& tables, const std::vector<int>& imageIndexList);
|
||||
void ExchangeBindFolderImage(const std::vector<BatchTableInfo>& tables, int imageIndex1, int imageIndex2);
|
||||
void ClearBindFolderImageList();
|
||||
void ClearBindFolderImageList(const std::vector<BatchTableInfo>& tables);
|
||||
|
||||
static int sane_ex_callback(SANE_Handle hdev, int code, void* data, unsigned int* len, void* param);
|
||||
|
||||
|
@ -384,5 +385,7 @@ namespace ver_2
|
|||
std::string m_currBatchId;
|
||||
std::string m_bindFolder;
|
||||
std::string m_bindNameMode;
|
||||
int m_bindNameWidth;
|
||||
int m_bindNameBase;
|
||||
};
|
||||
}
|
|
@ -1693,7 +1693,7 @@ namespace ver_2
|
|||
}
|
||||
}
|
||||
|
||||
char resp[1024] = { 0 };
|
||||
char* resp = new char[1024 + outZipBase64.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
|
@ -1722,6 +1722,7 @@ namespace ver_2
|
|||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
void WSUser::LocalImageDeskew(cJSON* json)
|
||||
|
@ -2829,10 +2830,18 @@ namespace ver_2
|
|||
bool find = false;
|
||||
std::string nameMode = GetJsonStringValue(json, "name_mode");
|
||||
if (!find)
|
||||
nameMode = "index";
|
||||
nameMode = "order";
|
||||
|
||||
int nameWidth = GetJsonIntValue(json, "name_width", &find);
|
||||
if (!find)
|
||||
nameWidth = 1;
|
||||
|
||||
int nameBase = GetJsonIntValue(json, "name_base", &find);
|
||||
if (!find)
|
||||
nameBase = 0;
|
||||
|
||||
std::string errInfo;
|
||||
int ret = GetManager()->BindFolder(folder, nameMode, errInfo);
|
||||
int ret = GetManager()->BindFolder(folder, nameMode, nameWidth, nameBase, errInfo);
|
||||
|
||||
bool findIden = false;
|
||||
std::string iden = GetJsonStringValue(json, "iden", &findIden);
|
||||
|
@ -3917,7 +3926,7 @@ namespace ver_2
|
|||
}
|
||||
}
|
||||
|
||||
char resp[1024] = { 0 };
|
||||
char* resp = new char[1024 + outZipBase64.size()];
|
||||
if (0 != ret)
|
||||
{
|
||||
if (findIden)
|
||||
|
@ -3946,6 +3955,7 @@ namespace ver_2
|
|||
}
|
||||
|
||||
SendResponse((const HGByte*)resp, (HGUInt)strlen(resp), HGTRUE);
|
||||
delete[] resp;
|
||||
}
|
||||
|
||||
void WSUser::ImageDeskew(cJSON* json)
|
||||
|
|
|
@ -340,7 +340,8 @@
|
|||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'local_make_zip_file',
|
||||
'file_path_list':['D:\\1.jpg','D:\\2.jpg']
|
||||
'file_path_list':['D:\\1.jpg','D:\\2.jpg'],
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -485,7 +486,9 @@
|
|||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'bind_folder',
|
||||
'folder':'D:\\111'
|
||||
'folder':'D:\\111',
|
||||
'name_width':1,
|
||||
'name_base':20
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -596,7 +599,7 @@
|
|||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'merge_image',
|
||||
'image_index_list':[0, 1, 2],
|
||||
'image_index_list':[0, 1],
|
||||
'mode':'horz',
|
||||
'align':'center',
|
||||
'interval':20,
|
||||
|
@ -608,7 +611,7 @@
|
|||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'make_multi_image',
|
||||
'image_index_list':[0, 1, 2],
|
||||
'image_index_list':[0, 1],
|
||||
'format':'tif',
|
||||
'tiff_compression':'jpeg',
|
||||
'tiff_jpeg_quality':60,
|
||||
|
@ -631,7 +634,8 @@
|
|||
{
|
||||
socket.send(JSON.stringify({
|
||||
'func':'make_zip_file',
|
||||
'image_index_list':[0, 1, 2]
|
||||
'image_index_list':[0, 1],
|
||||
'get_base64':true
|
||||
}));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue