2022-05-24 02:01:36 +00:00
# include " ManagerV2.h "
2022-06-16 01:37:26 +00:00
# include "base/HGDef.h"
# include "base/HGInc.h"
2022-05-23 10:29:23 +00:00
# include "base/HGBuffer.h"
# include "base/HGBase64.h"
# include "base/HGUtility.h"
2022-05-30 11:01:23 +00:00
# include "base/HGIni.h"
2022-05-23 10:29:23 +00:00
# include "base/HGInfo.h"
2022-05-30 11:01:23 +00:00
# include "base/HGTime.h"
2022-05-23 10:29:23 +00:00
# include "imgfmt/HGJpeg.h"
# include "imgfmt/HGOfd.h"
# include "imgfmt/HGPdf.h"
# include "imgfmt/HGTiff.h"
# include "imgfmt/HGImgFmt.h"
2022-06-01 10:36:22 +00:00
# include "imgproc/HGOCR.h"
# include "imgproc/HGImgProc.h"
2022-05-23 10:29:23 +00:00
# include "HGString.h"
2022-06-01 10:36:22 +00:00
extern " C "
{
# include "zip.h"
} ;
# include <curl/curl.h>
# include <list>
# include <algorithm>
2023-05-16 07:37:40 +00:00
# include "WSUser.h"
2022-05-23 10:29:23 +00:00
namespace ver_2
{
ManagerV2 : : ManagerV2 ( HGMsgPump msgPump )
: Manager ( msgPump )
{
2023-05-17 07:37:04 +00:00
m_lock = NULL ;
2022-05-30 11:01:23 +00:00
HGBase_CreateLock ( & m_lock ) ;
HGChar docsPath [ 256 ] ;
HGBase_GetDocumentsPath ( docsPath , 256 ) ;
HGChar procName [ 256 ] ;
HGBase_GetProcessName ( procName , 256 ) ;
HGChar defSavePath [ 256 ] ;
sprintf ( defSavePath , " %s%s/ " , docsPath , procName ) ;
m_globalCfg . fileSavePath = GetCfgStringValue ( " global " , " fileSavePath " , defSavePath ) ;
m_globalCfg . fileNamePrefix = GetCfgStringValue ( " global " , " fileNamePrefix " , " Huago " ) ;
m_globalCfg . fileNameMode = GetCfgStringValue ( " global " , " fileNameMode " , " date_time " ) ;
m_globalCfg . imageFormat = GetCfgStringValue ( " global " , " imageFormat " , " jpg " ) ;
m_globalCfg . imageJpegQuality = GetCfgIntValue ( " global " , " imageJpegQuality " , 80 ) ;
m_globalCfg . imageTiffCompression = GetCfgStringValue ( " global " , " imageTiffCompression " , " lzw " ) ;
m_globalCfg . imageTiffJpegQuality = GetCfgIntValue ( " global " , " imageTiffJpegQuality " , 80 ) ;
m_globalCfg . fileSavePath . push_back ( ' / ' ) ;
HGChar stdSavePath [ 256 ] ;
HGBase_StandardiseFileName ( m_globalCfg . fileSavePath . c_str ( ) , stdSavePath , 256 ) ;
m_globalCfg . fileSavePath = stdSavePath ;
2023-05-16 07:37:40 +00:00
m_user . clear ( ) ;
2023-05-17 07:37:04 +00:00
m_stopThread = HGFALSE ;
m_timeout = 0xFFFFFFFF ;
m_event = NULL ;
HGBase_CreateEvent ( HGFALSE , HGFALSE , & m_event ) ;
m_thread = NULL ;
HGBase_OpenThread ( ThreadFunc , this , & m_thread ) ;
2022-05-30 11:01:23 +00:00
m_initDevice = false ;
m_openDevice = false ;
m_devName . clear ( ) ;
2024-01-12 01:16:53 +00:00
m_sn . clear ( ) ;
2022-05-30 11:01:23 +00:00
m_devHandle = NULL ;
2022-06-15 11:07:55 +00:00
m_devParams . clear ( ) ;
2024-04-18 03:04:35 +00:00
m_initIden . clear ( ) ;
m_initHaveIden = false ;
2024-04-18 07:39:23 +00:00
m_scanUser = NULL ;
2024-04-18 03:04:35 +00:00
m_scanIden . clear ( ) ;
m_scanHaveIden = false ;
2022-08-01 07:58:12 +00:00
m_scanBlankCheck = false ;
2024-04-18 03:04:35 +00:00
m_scanLocalSave = true ;
m_scanGetBase64 = false ;
2022-05-30 11:01:23 +00:00
m_scanning = false ;
2022-06-01 10:36:22 +00:00
m_scanEvent = NULL ;
2023-11-14 04:38:12 +00:00
m_dpi = 200 ;
2024-04-23 09:50:11 +00:00
m_curBatchTime . clear ( ) ;
m_curImgIndex = 0 ;
2022-06-07 10:22:27 +00:00
HGChar cfgPath [ 256 ] ;
HGBase_GetConfigPath ( cfgPath , 256 ) ;
2022-06-09 10:11:44 +00:00
HGBase_CreateDir ( cfgPath ) ;
2022-06-09 09:30:04 +00:00
char oldDbPath [ 256 ] ;
2022-06-23 00:50:44 +00:00
sprintf ( oldDbPath , " %s%s " , cfgPath , " config2.db " ) ;
2022-06-09 09:30:04 +00:00
HGBase_DeleteFile ( oldDbPath ) ;
char newDbPath [ 256 ] ;
2022-06-23 00:50:44 +00:00
sprintf ( newDbPath , " %s%s " , cfgPath , " newConfig2.db " ) ;
2022-06-07 10:22:27 +00:00
m_sqlite = NULL ;
2022-06-09 09:30:04 +00:00
sqlite3_open_v2 ( newDbPath , & m_sqlite , SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE |
2022-06-07 10:22:27 +00:00
SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_SHAREDCACHE , NULL ) ;
if ( NULL ! = m_sqlite )
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " open database success " ) ;
2022-10-09 02:07:32 +00:00
// 删除旧配置表
sqlite3_exec ( m_sqlite , " delete from device_params " , NULL , NULL , NULL ) ;
2022-06-16 07:56:29 +00:00
// 保存路径表
sqlite3_exec ( m_sqlite , " create table save_filenames (filename text) " , NULL , NULL , NULL ) ;
// 设备配置表
2022-10-09 02:07:32 +00:00
sqlite3_exec ( m_sqlite , " create table device_params_2 (name text, title text, value_type text, value text) " , NULL , NULL , NULL ) ;
2022-06-16 07:56:29 +00:00
2022-06-07 10:22:27 +00:00
int ret = sqlite3_exec ( m_sqlite , " create table table_ (id integer primary key autoincrement, name text) " , NULL , NULL , NULL ) ;
if ( 0 = = ret )
{
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
2022-06-07 10:22:27 +00:00
assert ( 0 = = ret ) ;
2022-06-22 12:38:39 +00:00
do
{
ret = sqlite3_exec ( m_sqlite , " create table 'table_default' (id integer primary key autoincrement, format text, tag text, image blob, thumb blob) " , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
break ;
ret = sqlite3_exec ( m_sqlite , " create table 'table_default_idx' (id integer, idx integer) " , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
break ;
ret = sqlite3_exec ( m_sqlite , " insert into table_ (name) values ('default') " , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
break ;
} while ( 0 ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
}
else
{
2022-06-22 12:38:39 +00:00
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-22 07:41:59 +00:00
}
}
2022-06-09 09:51:07 +00:00
2022-06-16 09:52:10 +00:00
sqlite3_stmt * stmt = NULL ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_prepare ( m_sqlite , " select name from table_ order by id desc " , - 1 , & stmt , NULL ) ;
2022-06-16 09:52:10 +00:00
assert ( 0 = = ret ) ;
ret = sqlite3_step ( stmt ) ;
2022-06-22 12:38:39 +00:00
if ( SQLITE_ROW = = ret )
m_currBatchId = ( const char * ) sqlite3_column_text ( stmt , 0 ) ;
2022-06-16 09:52:10 +00:00
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
2022-06-07 10:22:27 +00:00
}
2022-10-27 09:19:58 +00:00
else
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " open database failed " ) ;
}
2022-06-11 06:18:33 +00:00
m_bindFolder . clear ( ) ;
m_bindNameMode . clear ( ) ;
2022-06-13 04:02:51 +00:00
m_bindNameWidth = 0 ;
m_bindNameBase = 0 ;
2022-06-21 10:37:41 +00:00
2022-06-16 07:56:29 +00:00
LoadSaveFilePathList ( m_saveFilePathList ) ;
2022-06-21 10:37:41 +00:00
RestoreSaveFilePathList ( m_saveFilePathList ) ;
2022-05-23 10:29:23 +00:00
}
ManagerV2 : : ~ ManagerV2 ( )
{
2022-06-06 10:51:34 +00:00
std : : string errInfo ;
DeinitDevice ( errInfo ) ;
2022-05-23 10:29:23 +00:00
2022-06-07 10:22:27 +00:00
if ( NULL ! = m_sqlite )
{
sqlite3_close_v2 ( m_sqlite ) ;
m_sqlite = NULL ;
}
2023-05-17 07:37:04 +00:00
m_stopThread = HGTRUE ;
HGBase_SetEvent ( m_event ) ;
HGBase_CloseThread ( m_thread ) ;
m_thread = NULL ;
HGBase_DestroyEvent ( m_event ) ;
m_event = NULL ;
2022-05-30 11:01:23 +00:00
HGBase_DestroyLock ( m_lock ) ;
m_lock = NULL ;
}
2023-05-17 07:37:04 +00:00
void ManagerV2 : : DeinitDev ( const DeinitDevParam * param )
{
assert ( NULL ! = param & & this = = param - > mgr ) ;
std : : string errInfo ;
DeinitDevice ( errInfo ) ;
}
2022-06-01 10:36:22 +00:00
void ManagerV2 : : CloseDev ( const CloseDevParam * param )
{
assert ( NULL ! = param & & this = = param - > mgr ) ;
if ( m_devName = = param - > devName )
{
2022-06-06 10:51:34 +00:00
std : : string errInfo ;
CloseDevice ( errInfo ) ;
2022-06-01 10:36:22 +00:00
}
}
2022-06-06 11:34:54 +00:00
void ManagerV2 : : ScanFinish ( const ScanFinishParam * param )
{
assert ( NULL ! = param & & this = = param - > mgr ) ;
std : : string errInfo ;
StopScan ( errInfo ) ;
}
2022-06-21 10:37:41 +00:00
void ManagerV2 : : AddSavedFile ( const AddSavedFileParam * param )
2022-06-16 09:52:10 +00:00
{
assert ( NULL ! = param & & this = = param - > mgr ) ;
m_saveFilePathList . push_back ( param - > fileName ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
2022-06-21 10:37:41 +00:00
void ManagerV2 : : RemoveSavedFile ( const RemoveSavedFileParam * param )
{
assert ( NULL ! = param & & this = = param - > mgr ) ;
2022-07-05 02:36:01 +00:00
std : : list < std : : string > : : iterator iter ;
2022-06-21 10:37:41 +00:00
for ( iter = m_saveFilePathList . begin ( ) ; iter ! = m_saveFilePathList . end ( ) ; + + iter )
{
if ( * iter = = param - > fileName )
{
m_saveFilePathList . erase ( iter ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
break ;
}
}
}
2023-05-16 07:37:40 +00:00
void ManagerV2 : : AddUser ( class WSUser * user )
{
assert ( NULL ! = user ) ;
HGBase_EnterLock ( m_lock ) ;
m_user . push_back ( user ) ;
2023-05-17 07:37:04 +00:00
m_timeout = 0xFFFFFFFF ;
HGBase_SetEvent ( m_event ) ;
2023-05-16 07:37:40 +00:00
HGBase_LeaveLock ( m_lock ) ;
}
void ManagerV2 : : RemoveUser ( class WSUser * user )
{
assert ( NULL ! = user ) ;
HGBase_EnterLock ( m_lock ) ;
std : : list < class WSUser * > : : iterator iter ;
for ( iter = m_user . begin ( ) ; iter ! = m_user . end ( ) ; + + iter )
{
if ( * iter = = user )
{
m_user . erase ( iter ) ;
2023-05-17 07:37:04 +00:00
if ( m_user . empty ( ) )
{
m_timeout = 1000 * 10 * 60 ;
HGBase_SetEvent ( m_event ) ;
}
2023-05-16 07:37:40 +00:00
break ;
}
}
2024-04-18 07:39:23 +00:00
if ( m_scanUser = = user )
m_scanUser = NULL ;
2023-05-16 07:37:40 +00:00
HGBase_LeaveLock ( m_lock ) ;
}
2022-05-23 10:29:23 +00:00
2022-06-06 10:51:34 +00:00
int ManagerV2 : : SetGlobalConfig ( const GlobalConfig & cfg , HGUInt mask , std : : string & errInfo )
2022-05-23 10:29:23 +00:00
{
2022-06-06 10:51:34 +00:00
errInfo = " 参数错误 " ;
if ( ( mask & GlobalConfig : : fileSavePathMask ) & & cfg . fileSavePath . empty ( ) )
return - 1 ;
2024-01-12 01:16:53 +00:00
if ( ( mask & GlobalConfig : : fileNameModeMask ) & & ( " date_time " ! = cfg . fileNameMode & & " random " ! = cfg . fileNameMode
2024-04-23 09:50:11 +00:00
& & " sn_date_time " ! = cfg . fileNameMode ) & & " folder_time_img_order " ! = cfg . fileNameMode )
2022-05-23 10:29:23 +00:00
return - 1 ;
2022-06-06 10:51:34 +00:00
if ( ( mask & GlobalConfig : : imageFormatMask ) & & ( " jpg " ! = cfg . imageFormat & & " bmp " ! = cfg . imageFormat & & " png " ! = cfg . imageFormat & & " tif " ! = cfg . imageFormat
& & " pdf " ! = cfg . imageFormat & & " ofd " ! = cfg . imageFormat & & " ocr-pdf " ! = cfg . imageFormat & & " ocr-ofd " ! = cfg . imageFormat ) )
2022-05-23 10:29:23 +00:00
return - 1 ;
2022-06-06 10:51:34 +00:00
if ( ( mask & GlobalConfig : : imageJpegQualityMask ) & & ( cfg . imageJpegQuality < 0 | | cfg . imageJpegQuality > 100 ) )
2022-05-23 10:29:23 +00:00
return - 1 ;
2022-06-06 10:51:34 +00:00
if ( ( mask & GlobalConfig : : imageTiffCompressionMask ) & & ( " none " ! = cfg . imageTiffCompression & & " lzw " ! = cfg . imageTiffCompression
& & " jpeg " ! = cfg . imageTiffCompression & & " ccitt-g4 " ! = cfg . imageTiffCompression ) )
2022-05-23 10:29:23 +00:00
return - 1 ;
2022-06-06 10:51:34 +00:00
if ( ( mask & GlobalConfig : : imageTiffJpegQualityMask ) & & ( cfg . imageTiffJpegQuality < 0 | | cfg . imageTiffJpegQuality > 100 ) )
2022-05-23 10:29:23 +00:00
return - 1 ;
2022-06-09 09:51:07 +00:00
HGBase_EnterLock ( m_lock ) ;
2022-06-06 10:51:34 +00:00
if ( mask & GlobalConfig : : fileSavePathMask )
{
std : : string fileSavePath = cfg . fileSavePath ;
fileSavePath . push_back ( ' / ' ) ;
HGChar stdFileSavePath [ 256 ] ;
HGBase_StandardiseFileName ( fileSavePath . c_str ( ) , stdFileSavePath , 256 ) ;
m_globalCfg . fileSavePath = stdFileSavePath ;
SetCfgStringValue ( " global " , " fileSavePath " , m_globalCfg . fileSavePath ) ;
}
if ( mask & GlobalConfig : : fileNamePrefixMask )
{
m_globalCfg . fileNamePrefix = cfg . fileNamePrefix ;
SetCfgStringValue ( " global " , " fileNamePrefix " , m_globalCfg . fileNamePrefix ) ;
2022-06-09 09:51:07 +00:00
}
2022-06-06 10:51:34 +00:00
if ( mask & GlobalConfig : : fileNameModeMask )
{
m_globalCfg . fileNameMode = cfg . fileNameMode ;
SetCfgStringValue ( " global " , " fileNameMode " , m_globalCfg . fileNameMode ) ;
}
if ( mask & GlobalConfig : : imageFormatMask )
{
m_globalCfg . imageFormat = cfg . imageFormat ;
SetCfgStringValue ( " global " , " imageFormat " , m_globalCfg . imageFormat ) ;
}
if ( mask & GlobalConfig : : imageJpegQualityMask )
{
m_globalCfg . imageJpegQuality = cfg . imageJpegQuality ;
SetCfgIntValue ( " global " , " imageJpegQuality " , m_globalCfg . imageJpegQuality ) ;
}
if ( mask & GlobalConfig : : imageTiffCompressionMask )
{
m_globalCfg . imageTiffCompression = cfg . imageTiffCompression ;
SetCfgStringValue ( " global " , " imageTiffCompression " , m_globalCfg . imageTiffCompression ) ;
}
if ( mask & GlobalConfig : : imageTiffJpegQualityMask )
{
m_globalCfg . imageTiffJpegQuality = cfg . imageTiffJpegQuality ;
SetCfgIntValue ( " global " , " imageTiffJpegQuality " , m_globalCfg . imageTiffJpegQuality ) ;
}
2022-06-01 10:36:22 +00:00
HGBase_LeaveLock ( m_lock ) ;
2022-05-30 11:01:23 +00:00
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-23 10:29:23 +00:00
return 0 ;
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : GetGlobalConfig ( GlobalConfig & cfg , std : : string & errInfo )
2022-05-23 10:29:23 +00:00
{
2022-05-30 11:01:23 +00:00
cfg = m_globalCfg ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-23 10:29:23 +00:00
return 0 ;
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : LoadLocalImage ( const std : : string & imagePath , std : : string & imgBase64 , std : : string & errInfo )
2022-05-23 10:29:23 +00:00
{
imgBase64 . clear ( ) ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-05-23 10:29:23 +00:00
HGUInt imgType = 0 ;
2022-05-30 11:01:23 +00:00
HGImgFmt_GetImgFmtType ( imagePath . c_str ( ) , & imgType ) ;
2022-05-23 10:29:23 +00:00
if ( 0 = = imgType )
return - 1 ;
2022-05-30 11:01:23 +00:00
int ret = LoadBase64 ( imagePath , imgBase64 ) ;
2022-05-23 11:01:52 +00:00
if ( 0 ! = ret )
return ret ;
2022-05-23 10:29:23 +00:00
std : : string prefix = " data:image/jpeg;base64, " ;
if ( HGIMGFMT_TYPE_BMP = = imgType )
prefix = " data:image/bmp;base64, " ;
else if ( HGIMGFMT_TYPE_PNG = = imgType )
prefix = " data:image/png;base64, " ;
else if ( HGIMGFMT_TYPE_TIFF = = imgType )
prefix = " data:image/tiff;base64, " ;
else if ( HGIMGFMT_TYPE_PDF = = imgType )
prefix = " data:image/pdf;base64, " ;
else if ( HGIMGFMT_TYPE_OFD = = imgType )
prefix = " data:image/ofd;base64, " ;
imgBase64 . insert ( 0 , prefix ) ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-23 10:29:23 +00:00
return 0 ;
}
2022-06-22 07:41:59 +00:00
int ManagerV2 : : SaveLocalImage ( const std : : string & imgBase64 , bool temp , std : : string & imagePath , std : : string & errInfo )
2022-05-23 10:29:23 +00:00
{
imagePath . clear ( ) ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-05-23 10:29:23 +00:00
size_t pos = imgBase64 . find ( ' , ' ) ;
if ( std : : string : : npos = = pos )
return - 1 ;
std : : string prefix = imgBase64 . substr ( 0 , pos + 1 ) ;
std : : string suffix = " jpg " ;
if ( " data:image/bmp;base64, " = = prefix )
suffix = " bmp " ;
else if ( " data:image/png;base64, " = = prefix )
suffix = " png " ;
else if ( " data:image/tiff;base64, " = = prefix )
suffix = " tif " ;
else if ( " data:image/pdf;base64, " = = prefix )
suffix = " pdf " ;
else if ( " data:image/ofd;base64, " = = prefix )
suffix = " ofd " ;
2022-06-22 07:41:59 +00:00
std : : string imagePath2 = GetFilePath ( temp , suffix ) ;
2022-05-23 11:01:52 +00:00
int ret = SaveBase64 ( imgBase64 . c_str ( ) + pos + 1 , imagePath2 ) ;
if ( 0 ! = ret )
return ret ;
2022-05-30 11:01:23 +00:00
imagePath = imagePath2 ;
2022-06-22 07:41:59 +00:00
if ( ! temp )
{
m_saveFilePathList . push_back ( imagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-23 11:01:52 +00:00
return 0 ;
2022-05-23 10:29:23 +00:00
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : DeleteLocalFile ( const std : : string & filePath , std : : string & errInfo )
2022-05-23 10:29:23 +00:00
{
2022-05-30 11:01:23 +00:00
int ret = - 1 ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-06-01 10:36:22 +00:00
2022-07-05 02:36:01 +00:00
std : : list < std : : string > : : iterator iter ;
2022-06-21 10:37:41 +00:00
for ( iter = m_saveFilePathList . begin ( ) ; iter ! = m_saveFilePathList . end ( ) ; + + iter )
2022-05-30 11:01:23 +00:00
{
2022-06-21 10:37:41 +00:00
if ( filePath = = * iter )
2022-05-30 11:01:23 +00:00
{
if ( HGBASE_ERR_OK = = HGBase_DeleteFile ( filePath . c_str ( ) ) )
{
2022-06-21 10:37:41 +00:00
m_saveFilePathList . erase ( iter ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-30 11:01:23 +00:00
ret = 0 ;
}
break ;
}
}
return ret ;
2022-05-23 10:29:23 +00:00
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : ClearGlobalFileSavePath ( std : : string & errInfo )
2022-05-23 11:01:52 +00:00
{
2022-06-21 10:37:41 +00:00
std : : list < std : : string > : : const_iterator iter ;
for ( iter = m_saveFilePathList . begin ( ) ; iter ! = m_saveFilePathList . end ( ) ; + + iter )
2022-05-30 11:01:23 +00:00
{
2022-06-21 10:37:41 +00:00
HGBase_DeleteFile ( ( * iter ) . c_str ( ) ) ;
2022-05-30 11:01:23 +00:00
}
2022-06-21 10:37:41 +00:00
m_saveFilePathList . clear ( ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-23 11:01:52 +00:00
return 0 ;
}
2022-06-21 10:37:41 +00:00
int ManagerV2 : : UploadLocalFile ( const std : : string & filePath , const std : : string & remoteFilePath , const std : : string & uploadMode ,
const std : : string & httpHost , int httpPort , const std : : string & httpPath , const std : : string & ftpUser , const std : : string & ftpPassword ,
const std : : string & ftpHost , int ftpPort , std : : string & errInfo )
{
errInfo = " 错误 " ;
if ( filePath . empty ( ) | | remoteFilePath . empty ( ) )
return - 1 ;
if ( " http " ! = uploadMode & & " ftp " ! = uploadMode )
return - 1 ;
int ret = - 1 ;
if ( " http " = = uploadMode )
{
ret = HttpUpload ( httpHost , httpPort , httpPath , filePath , remoteFilePath ) ;
}
else
{
ret = FtpUpload ( ftpUser , ftpPassword , ftpHost , ftpPort , filePath , remoteFilePath ) ;
}
if ( 0 = = ret )
errInfo . clear ( ) ;
return ret ;
}
2022-05-23 11:01:52 +00:00
int ManagerV2 : : MergeLocalImage ( const std : : vector < std : : string > & imagePathList , const std : : string & mode ,
2022-06-22 07:41:59 +00:00
const std : : string & align , int interval , bool temp , std : : string & outImagePath , std : : string & errInfo )
2022-05-23 11:01:52 +00:00
{
2022-06-01 10:36:22 +00:00
outImagePath . clear ( ) ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-06-01 10:36:22 +00:00
if ( imagePathList . empty ( ) | | interval < 0 )
return - 1 ;
if ( " horz " = = mode )
{
if ( " top " ! = align & & " bottom " ! = align & & " center " ! = align )
return - 1 ;
}
else if ( " vert " = = mode )
{
if ( " left " ! = align & & " right " ! = align & & " center " ! = align )
return - 1 ;
}
else
{
return - 1 ;
}
HGUInt width = 0 , height = 0 ;
for ( int i = 0 ; i < ( int ) imagePathList . size ( ) ; + + i )
{
HGImgFmtLoadInfo loadInfo ;
if ( HGBASE_ERR_OK = = HGImgFmt_LoadImage ( imagePathList [ i ] . c_str ( ) , 0 , & loadInfo , 0 , 0 , NULL ) )
{
if ( " horz " = = mode )
{
if ( 0 ! = width )
width + = interval ;
width + = loadInfo . width ;
if ( loadInfo . height > height )
height = loadInfo . height ;
}
else
{
if ( 0 ! = height )
height + = interval ;
height + = loadInfo . height ;
if ( loadInfo . width > width )
width = loadInfo . width ;
}
}
}
HGImage outImage = NULL ;
HGBase_CreateImage ( width , height , HGBASE_IMGTYPE_RGB , HGBASE_IMGORIGIN_TOP , & outImage ) ;
if ( NULL = = outImage )
return - 1 ;
HGImageInfo outImageInfo ;
HGBase_GetImageInfo ( outImage , & outImageInfo ) ;
HGByte * outImageData = NULL ;
HGBase_GetImageData ( outImage , & outImageData ) ;
memset ( outImageData , 255 , outImageInfo . widthStep * outImageInfo . height ) ;
HGUInt start = 0 ;
for ( int i = 0 ; i < ( int ) imagePathList . size ( ) ; + + i )
{
HGImage img = NULL ;
HGImgFmt_LoadImage ( imagePathList [ i ] . c_str ( ) , 0 , NULL , HGBASE_IMGTYPE_RGB , HGBASE_IMGORIGIN_TOP , & img ) ;
if ( NULL ! = img )
{
HGImageInfo imgInfo ;
HGBase_GetImageInfo ( img , & imgInfo ) ;
if ( 0 ! = start )
start + = interval ;
HGImageRoi outImageRoi ;
if ( " horz " = = mode )
{
outImageRoi . left = start ;
outImageRoi . top = 0 ;
if ( " bottom " = = align )
outImageRoi . top = height - imgInfo . height ;
else if ( " center " = = align )
outImageRoi . top = ( height - imgInfo . height ) / 2 ;
start + = imgInfo . width ;
}
else
{
outImageRoi . left = 0 ;
if ( " right " = = align )
outImageRoi . left = width - imgInfo . width ;
else if ( " center " = = align )
outImageRoi . left = ( width - imgInfo . width ) / 2 ;
outImageRoi . top = start ;
start + = imgInfo . height ;
}
outImageRoi . right = outImageRoi . left + imgInfo . width ;
outImageRoi . bottom = outImageRoi . top + imgInfo . height ;
HGBase_SetImageROI ( outImage , & outImageRoi ) ;
HGBase_CopyImage ( img , outImage ) ;
HGBase_ResetImageROI ( outImage ) ;
HGBase_DestroyImage ( img ) ;
}
}
2022-06-22 07:41:59 +00:00
int ret = SaveImage ( outImage , temp , outImagePath ) ;
2022-06-01 10:36:22 +00:00
if ( 0 = = ret )
{
2022-06-22 07:41:59 +00:00
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-06-01 10:36:22 +00:00
}
HGBase_DestroyImage ( outImage ) ;
return ret ;
2022-05-23 11:01:52 +00:00
}
int ManagerV2 : : LocalMakeMultiImage ( const std : : vector < std : : string > & imagePathList , const std : : string & format ,
2022-06-22 07:41:59 +00:00
const std : : string & tiffCompression , int tiffJpegQuality , bool temp , std : : string & outImagePath , std : : string & errInfo )
2022-05-23 11:01:52 +00:00
{
2022-06-01 10:36:22 +00:00
outImagePath . clear ( ) ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-06-01 10:36:22 +00:00
if ( imagePathList . empty ( ) )
return - 1 ;
if ( " tif " ! = format & & " pdf " ! = format & & " ofd " ! = format )
return - 1 ;
if ( " none " ! = tiffCompression & & " lzw " ! = tiffCompression & & " jpeg " ! = tiffCompression
& & " ccitt-g4 " ! = tiffCompression )
return - 1 ;
if ( tiffJpegQuality < 0 | | tiffJpegQuality > 100 )
return - 1 ;
int ret = - 1 ;
2022-06-22 07:41:59 +00:00
std : : string outImagePath2 = GetFilePath ( temp , format ) ;
2022-06-01 10:36:22 +00:00
HGImgFmtWriter writer = NULL ;
HGImgFmt_OpenImageWriter ( outImagePath2 . c_str ( ) , 0 , & writer ) ;
if ( NULL ! = writer )
{
for ( int i = 0 ; i < ( int ) imagePathList . size ( ) ; + + i )
{
HGImage img = NULL ;
HGImgFmt_LoadImage ( imagePathList [ i ] . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & img ) ;
if ( NULL ! = img )
{
HGImgFmtSaveInfo saveInfo ;
saveInfo . jpegQuality = 80 ;
saveInfo . tiffJpegQuality = tiffJpegQuality ;
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_LZW ;
if ( " none " = = tiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_NONE ;
else if ( " jpeg " = = tiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_JPEG ;
else if ( " ccitt-g4 " = = tiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4 ;
if ( HGBASE_ERR_OK = = HGImgFmt_SaveImageToWriter ( writer , img , & saveInfo ) )
{
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-06-01 10:36:22 +00:00
ret = 0 ;
}
HGBase_DestroyImage ( img ) ;
}
}
HGImgFmt_CloseImageWriter ( writer ) ;
}
if ( 0 ! = ret )
{
HGBase_DeleteFile ( outImagePath2 . c_str ( ) ) ;
return ret ;
}
outImagePath = outImagePath2 ;
2022-06-22 07:41:59 +00:00
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
return 0 ;
2022-05-23 11:01:52 +00:00
}
2022-06-22 07:41:59 +00:00
int ManagerV2 : : SplitLocalImage ( const std : : string & imagePath , const std : : string & mode , int location , bool temp ,
2022-06-06 10:51:34 +00:00
std : : vector < std : : string > & outImagePathList , std : : string & errInfo )
2022-05-23 11:01:52 +00:00
{
2022-06-01 10:36:22 +00:00
outImagePathList . clear ( ) ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-06-01 10:36:22 +00:00
if ( imagePath . empty ( ) | | location < 0 )
return - 1 ;
if ( " horz " ! = mode & & " vert " ! = mode )
return - 1 ;
int ret = - 1 ;
HGImage image = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & image ) ;
{
HGImageInfo imageInfo ;
HGBase_GetImageInfo ( image , & imageInfo ) ;
for ( int i = 0 ; i < 2 ; + + i )
{
HGImageRoi imageRoi ;
if ( " horz " = = mode )
{
imageRoi . top = 0 ;
imageRoi . bottom = imageInfo . height ;
if ( 0 = = i )
{
imageRoi . left = 0 ;
imageRoi . right = ( HGUInt ) location ;
}
else
{
imageRoi . left = ( HGUInt ) location ;
imageRoi . right = imageInfo . width ;
}
}
else
{
imageRoi . left = 0 ;
imageRoi . right = imageInfo . width ;
if ( 0 = = i )
{
imageRoi . top = 0 ;
imageRoi . bottom = ( HGUInt ) location ;
}
else
{
imageRoi . top = ( HGUInt ) location ;
imageRoi . bottom = imageInfo . height ;
}
}
if ( HGBASE_ERR_OK = = HGBase_SetImageROI ( image , & imageRoi ) )
{
HGImage img = NULL ;
HGBase_CloneImage ( image , 0 , 0 , & img ) ;
if ( NULL ! = img )
{
std : : string imgPath ;
2022-06-22 07:41:59 +00:00
if ( 0 = = SaveImage ( img , temp , imgPath ) )
2022-06-01 10:36:22 +00:00
{
outImagePathList . push_back ( imgPath ) ;
2022-06-22 07:41:59 +00:00
if ( ! temp )
{
m_saveFilePathList . push_back ( imgPath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-06-01 10:36:22 +00:00
ret = 0 ;
}
HGBase_DestroyImage ( img ) ;
}
HGBase_ResetImageROI ( image ) ;
}
}
HGBase_DestroyImage ( image ) ;
}
return ret ;
2022-05-23 11:01:52 +00:00
}
2022-06-11 09:54:04 +00:00
int ManagerV2 : : LocalMakeZipFile ( const std : : vector < std : : string > & filePathList , const std : : vector < std : : string > & nameList ,
2023-10-23 08:22:47 +00:00
const std : : string & zipPath , bool temp , std : : string & outZipPath , std : : string & errInfo )
2022-05-23 11:01:52 +00:00
{
2022-06-01 10:36:22 +00:00
outZipPath . clear ( ) ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-06-01 10:36:22 +00:00
if ( filePathList . empty ( ) )
return - 1 ;
2022-06-11 09:54:04 +00:00
if ( ! nameList . empty ( ) )
{
if ( nameList . size ( ) ! = filePathList . size ( ) )
return - 1 ;
for ( int i = 0 ; i < ( int ) nameList . size ( ) ; + + i )
{
if ( nameList [ i ] . empty ( ) )
return - 1 ;
}
}
2022-06-01 10:36:22 +00:00
2022-06-22 07:41:59 +00:00
std : : string outZipPath2 = GetFilePath ( temp , " zip " ) ;
2023-10-23 08:22:47 +00:00
if ( ! zipPath . empty ( ) )
outZipPath2 = zipPath ;
2022-06-01 10:36:22 +00:00
int error = 0 ;
zip * z = zip_open ( StdStringToUtf8 ( outZipPath2 ) . c_str ( ) , ZIP_CREATE | ZIP_TRUNCATE , & error ) ;
if ( NULL = = z )
{
2022-11-23 03:17:13 +00:00
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " ManagerV1::ExportZipFile Create File Fail %s " , outZipPath2 . c_str ( ) ) ;
2022-06-01 10:36:22 +00:00
return - 1 ;
}
int ret = - 1 ;
for ( int i = 0 ; i < ( int ) filePathList . size ( ) ; + + i )
{
zip_source_t * s = zip_source_file ( z , StdStringToUtf8 ( filePathList [ i ] ) . c_str ( ) , 0 , 0 ) ;
if ( NULL ! = s )
{
2022-06-11 09:54:04 +00:00
std : : string zipName ;
if ( ! nameList . empty ( ) )
{
zipName = nameList [ i ] ;
}
else
{
HGChar name [ 256 ] ;
HGBase_GetFileName ( filePathList [ i ] . c_str ( ) , name , 256 ) ;
zipName = name ;
}
if ( zip_file_add ( z , StdStringToUtf8 ( zipName ) . c_str ( ) , s , ZIP_FL_OVERWRITE ) > = 0 )
2022-06-01 10:36:22 +00:00
{
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-06-01 10:36:22 +00:00
ret = 0 ;
}
else
{
zip_source_free ( s ) ;
}
}
}
zip_close ( z ) ;
z = NULL ;
if ( 0 ! = ret )
{
HGBase_DeleteFile ( outZipPath2 . c_str ( ) ) ;
return ret ;
}
outZipPath = outZipPath2 ;
2022-06-22 07:41:59 +00:00
if ( ! temp )
{
m_saveFilePathList . push_back ( outZipPath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
return 0 ;
2022-05-23 11:01:52 +00:00
}
2022-06-23 03:35:17 +00:00
int ManagerV2 : : LocalImageDeskew ( const std : : string & imagePath , bool autoCrop , bool deskew , bool fillBlank , int width , int height ,
bool temp , std : : string & outImagePath , std : : string & errInfo )
2022-05-23 11:01:52 +00:00
{
2022-06-01 10:36:22 +00:00
outImagePath . clear ( ) ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-06-01 10:36:22 +00:00
2022-06-23 07:22:29 +00:00
if ( imagePath . empty ( ) | | width < 0 | | height < 0 )
2022-06-01 10:36:22 +00:00
return - 1 ;
int ret = - 1 ;
HGImage image = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & image ) ;
if ( NULL ! = image )
{
HGImage img = NULL ;
2022-07-05 02:36:01 +00:00
HGImgProc_ImageAutoCrop ( image , ( HGBool ) autoCrop , ( HGBool ) deskew , ( HGBool ) fillBlank , NULL ,
2022-06-23 03:35:17 +00:00
( HGUInt ) width , ( HGUInt ) height , 0 , HGBASE_IMGORIGIN_TOP , & img ) ;
2022-06-01 10:36:22 +00:00
if ( NULL ! = img )
{
2022-06-22 07:41:59 +00:00
if ( 0 = = SaveImage ( img , temp , outImagePath ) )
2022-06-01 10:36:22 +00:00
{
2022-06-22 07:41:59 +00:00
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-06-01 10:36:22 +00:00
ret = 0 ;
}
HGBase_DestroyImage ( img ) ;
}
HGBase_DestroyImage ( image ) ;
}
return ret ;
2022-05-23 11:01:52 +00:00
}
2022-06-14 10:22:23 +00:00
static int tolower ( int c )
{
if ( c > = ' A ' & & c < = ' Z ' )
{
return c + ' a ' - ' A ' ;
}
else
{
return c ;
}
}
static int htoi ( char s [ ] )
{
int i ;
int n = 0 ;
if ( s [ 0 ] = = ' 0 ' & & ( s [ 1 ] = = ' x ' | | s [ 1 ] = = ' X ' ) )
{
i = 2 ;
}
else
{
i = 0 ;
}
for ( ; ( s [ i ] > = ' 0 ' & & s [ i ] < = ' 9 ' ) | | ( s [ i ] > = ' a ' & & s [ i ] < = ' z ' ) | | ( s [ i ] > = ' A ' & & s [ i ] < = ' Z ' ) ; + + i )
{
if ( tolower ( s [ i ] ) > ' 9 ' )
{
n = 16 * n + ( 10 + tolower ( s [ i ] ) - ' a ' ) ;
}
else
{
n = 16 * n + ( tolower ( s [ i ] ) - ' 0 ' ) ;
}
}
return n ;
}
2022-06-21 05:42:22 +00:00
static bool GetColor ( const std : : string & colorText , HGUInt & r , HGUInt & g , HGUInt & b )
{
if ( 7 ! = colorText . size ( ) )
return false ;
if ( ' # ' ! = colorText [ 0 ] )
return false ;
for ( int i = 1 ; i < ( int ) colorText . size ( ) ; + + i )
{
if ( ( colorText [ i ] > = ' 0 ' & & colorText [ i ] < = ' 9 ' ) | | ( colorText [ i ] > = ' a ' & & colorText [ i ] < = ' f ' )
| | ( colorText [ i ] > = ' A ' & & colorText [ i ] < = ' F ' ) )
{
}
else
{
return false ;
}
}
char colorR [ 3 ] = { 0 } ;
char colorG [ 3 ] = { 0 } ;
char colorB [ 3 ] = { 0 } ;
strncpy ( colorR , colorText . c_str ( ) + 1 , 2 ) ;
strncpy ( colorG , colorText . c_str ( ) + 3 , 2 ) ;
strncpy ( colorB , colorText . c_str ( ) + 5 , 2 ) ;
r = htoi ( colorR ) ;
g = htoi ( colorG ) ;
b = htoi ( colorB ) ;
return true ;
}
2022-06-13 11:56:43 +00:00
int ManagerV2 : : LocalImageAddWatermark ( const std : : string & imagePath , const std : : string & text , const std : : string & textColor , int textOpacity , const std : : string & textPos ,
int marginLeft , int marginTop , int marginRight , int marginBottom , int locationX , int locationY , const std : : string & fontName ,
2022-06-22 07:41:59 +00:00
int fontSize , bool fontBold , bool fontUnderline , bool fontItalic , bool fontStrikeout , bool temp , std : : string & outImagePath , std : : string & errInfo )
2022-06-13 11:56:43 +00:00
{
outImagePath . clear ( ) ;
errInfo = " 错误 " ;
2022-06-21 05:42:22 +00:00
if ( imagePath . empty ( ) | | text . empty ( ) | | textColor . empty ( ) | | textOpacity < 0 | | textOpacity > 255 | | marginLeft < 0 | | marginTop < 0
2022-06-13 11:56:43 +00:00
| | marginRight < 0 | | marginBottom < 0 | | fontName . empty ( ) | | fontSize < = 0 )
return - 1 ;
HGUInt posType = 0 ;
if ( " left " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_LEFT ;
else if ( " top " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_TOP ;
else if ( " right " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_RIGHT ;
else if ( " bottom " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_BOTTOM ;
else if ( " left_top " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_LEFTTOP ;
else if ( " right_top " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_RIGHTTOP ;
else if ( " left_bottom " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_LEFTBOTTOM ;
else if ( " right_bottom " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_RIGHTBOTTOM ;
else if ( " center " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_CENTER ;
else if ( " location " = = textPos )
posType = HGIMGPROC_WMPOSTYPE_LOCATION ;
if ( 0 = = posType )
{
return - 1 ;
}
2022-06-21 05:42:22 +00:00
HGUInt r , g , b ;
if ( ! GetColor ( textColor , r , g , b ) )
2022-06-14 10:22:23 +00:00
{
2022-06-21 05:42:22 +00:00
return - 1 ;
2022-06-14 10:22:23 +00:00
}
2022-06-13 11:56:43 +00:00
int ret = - 1 ;
HGImage image = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & image ) ;
if ( NULL ! = image )
{
HGImageRoi roi ;
HGBase_GetImageROI ( image , & roi ) ;
if ( HGIMGPROC_WMPOSTYPE_LEFT = = posType )
{
roi . left + = marginLeft ;
}
else if ( HGIMGPROC_WMPOSTYPE_TOP = = posType )
{
roi . top + = marginTop ;
}
else if ( HGIMGPROC_WMPOSTYPE_RIGHT = = posType )
{
roi . right - = marginRight ;
}
else if ( HGIMGPROC_WMPOSTYPE_BOTTOM = = posType )
{
roi . bottom - = marginBottom ;
}
else if ( HGIMGPROC_WMPOSTYPE_LEFTTOP = = posType )
{
roi . left + = marginLeft ;
roi . top + = marginTop ;
}
else if ( HGIMGPROC_WMPOSTYPE_RIGHTTOP = = posType )
{
roi . top + = marginTop ;
roi . right - = marginRight ;
}
else if ( HGIMGPROC_WMPOSTYPE_LEFTBOTTOM = = posType )
{
roi . left + = marginLeft ;
roi . bottom - = marginBottom ;
}
else if ( HGIMGPROC_WMPOSTYPE_RIGHTBOTTOM = = posType )
{
roi . right - = marginRight ;
roi . bottom - = marginBottom ;
}
HGImgWatermarkFontParam fontParam ;
strcpy ( fontParam . foneName , fontName . c_str ( ) ) ;
fontParam . fontSize = fontSize ;
fontParam . bold = fontBold ;
fontParam . underline = fontUnderline ;
fontParam . italic = fontItalic ;
fontParam . strikeout = fontStrikeout ;
2022-06-14 10:22:23 +00:00
HGColor color = HG_MAKECOLOR ( r , g , b , textOpacity ) ;
2022-06-14 10:43:40 +00:00
if ( HGBASE_ERR_OK = = HGBase_SetImageROI ( image , & roi )
2022-06-13 11:56:43 +00:00
& & HGBASE_ERR_OK = = HGImgProc_AddImageWatermark ( image , text . c_str ( ) , color , posType ,
locationX , locationY , & fontParam ) )
{
2022-06-22 07:41:59 +00:00
if ( 0 = = SaveImage ( image , temp , outImagePath ) )
2022-06-13 11:56:43 +00:00
{
2022-06-22 07:41:59 +00:00
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
2022-07-05 02:36:01 +00:00
2022-06-13 11:56:43 +00:00
errInfo . clear ( ) ;
ret = 0 ;
}
}
HGBase_DestroyImage ( image ) ;
}
return ret ;
}
2022-06-21 05:42:22 +00:00
int ManagerV2 : : LocalImageDecontamination ( const std : : string & imagePath , const std : : string mode , const std : : string & color ,
2022-06-22 07:41:59 +00:00
int x , int y , int width , int height , bool temp , std : : string & outImagePath , std : : string & errInfo )
2022-06-21 05:42:22 +00:00
{
outImagePath . clear ( ) ;
errInfo = " 错误 " ;
if ( imagePath . empty ( ) | | mode . empty ( ) | | color . empty ( ) | | x < 0 | | y < 0 | | width < = 0 | | height < = 0 )
return - 1 ;
if ( " inside " ! = mode & & " outside " ! = mode )
return - 1 ;
HGUInt r , g , b ;
if ( ! GetColor ( color , r , g , b ) )
{
return - 1 ;
}
int ret = - 1 ;
HGImage image = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & image ) ;
if ( NULL ! = image )
{
HGUInt decoType = HGIMGPROC_DECOTYPE_INSIDE ;
if ( " outside " = = mode )
decoType = HGIMGPROC_DECOTYPE_OUTSIDE ;
if ( HGBASE_ERR_OK = = HGImgProc_ImageDecontamination ( image , image , decoType , x , y ,
width , height , HG_MAKECOLOR ( r , g , b , 0 ) ) )
{
2022-06-22 07:41:59 +00:00
if ( 0 = = SaveImage ( image , temp , outImagePath ) )
2022-06-21 05:42:22 +00:00
{
2022-06-22 07:41:59 +00:00
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
2022-07-05 02:36:01 +00:00
2022-06-21 05:42:22 +00:00
errInfo . clear ( ) ;
ret = 0 ;
}
}
HGBase_DestroyImage ( image ) ;
}
return ret ;
}
2022-06-23 03:35:17 +00:00
int ManagerV2 : : LocalImageDirectionCorrect ( const std : : string & imagePath , bool temp , std : : string & outImagePath , std : : string & errInfo )
{
outImagePath . clear ( ) ;
errInfo = " 错误 " ;
if ( imagePath . empty ( ) )
return - 1 ;
int ret = - 1 ;
HGImage image = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & image ) ;
if ( NULL ! = image )
{
HGImage destImage = NULL ;
HGOCRMgr ocrMgr = NULL ;
2022-10-22 05:20:20 +00:00
HGImgProc_CreateOCRMgr ( 0 , & ocrMgr ) ;
2022-06-23 03:35:17 +00:00
if ( NULL ! = ocrMgr )
{
HGImageInfo imgInfo ;
HGBase_GetImageInfo ( image , & imgInfo ) ;
HGUInt direct = 0 ;
HGImgProc_ImageTextDirectOCR ( ocrMgr , image , & direct ) ;
if ( HGIMGPROC_OCRTEXTDIRECT_RIGHT = = direct )
{
HGBase_CreateImage ( imgInfo . height , imgInfo . width , imgInfo . type , imgInfo . origin , & destImage ) ;
HGBase_ImageRotateLeft ( image , destImage ) ;
}
else if ( HGIMGPROC_OCRTEXTDIRECT_LEFT = = direct )
{
HGBase_CreateImage ( imgInfo . height , imgInfo . width , imgInfo . type , imgInfo . origin , & destImage ) ;
HGBase_ImageRotateRight ( image , destImage ) ;
}
else if ( HGIMGPROC_OCRTEXTDIRECT_180 = = direct )
{
HGBase_CreateImage ( imgInfo . width , imgInfo . height , imgInfo . type , imgInfo . origin , & destImage ) ;
HGBase_ImageRotate180 ( image , destImage ) ;
}
else
{
HGBase_CloneImage ( image , imgInfo . type , imgInfo . origin , & destImage ) ;
}
HGImgProc_DestroyOCRMgr ( ocrMgr ) ;
}
if ( NULL ! = destImage )
{
if ( 0 = = SaveImage ( destImage , temp , outImagePath ) )
{
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
errInfo . clear ( ) ;
ret = 0 ;
}
HGBase_DestroyImage ( destImage ) ;
}
HGBase_DestroyImage ( image ) ;
}
return ret ;
}
2022-07-11 08:40:21 +00:00
int ManagerV2 : : LocalImageClip ( const std : : string & imagePath , int x , int y , int width , int height ,
bool temp , std : : string & outImagePath , std : : string & errInfo )
{
outImagePath . clear ( ) ;
errInfo = " 错误 " ;
if ( imagePath . empty ( ) | | x < 0 | | y < 0 | | width < = 0 | | height < = 0 )
return - 1 ;
int ret = - 1 ;
HGImage image = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & image ) ;
if ( NULL ! = image )
{
HGImageRoi roi ;
roi . left = x ;
roi . top = y ;
roi . right = roi . left + width ;
roi . bottom = roi . top + height ;
if ( HGBASE_ERR_OK = = HGBase_SetImageROI ( image , & roi ) )
{
HGImage image2 = NULL ;
if ( HGBASE_ERR_OK = = HGBase_CloneImage ( image , 0 , 0 , & image2 ) )
{
if ( 0 = = SaveImage ( image2 , temp , outImagePath ) )
{
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
errInfo . clear ( ) ;
ret = 0 ;
}
HGBase_DestroyImage ( image2 ) ;
}
}
HGBase_DestroyImage ( image ) ;
}
return ret ;
}
2024-03-27 06:08:21 +00:00
int ManagerV2 : : LocalImageFadeBkColor ( const std : : string & imagePath , bool temp , std : : string & outImagePath , std : : string & errInfo )
{
outImagePath . clear ( ) ;
errInfo = " 错误 " ;
if ( imagePath . empty ( ) )
return - 1 ;
int ret = - 1 ;
HGImage image = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & image ) ;
if ( NULL ! = image )
{
HGImgFaceBkColorParam param ;
param . threshold = 100 ;
param . offset = 0 ;
param . range = 40 ;
if ( HGBASE_ERR_OK = = HGImgProc_ImageFadeBkColor ( image , image , & param ) )
{
if ( 0 = = SaveImage ( image , temp , outImagePath ) )
{
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
errInfo . clear ( ) ;
ret = 0 ;
}
}
HGBase_DestroyImage ( image ) ;
}
return ret ;
}
int ManagerV2 : : LocalImageAdjustColors ( const std : : string & imagePath , int brightness , int contrast , double gamma ,
bool temp , std : : string & outImagePath , std : : string & errInfo )
{
outImagePath . clear ( ) ;
errInfo = " 错误 " ;
if ( imagePath . empty ( ) | | brightness < - 255 | | brightness > 255 | | contrast < - 127 | | contrast > 127
| | gamma < 0.1 | | gamma > 5.0 )
return - 1 ;
int ret = - 1 ;
HGImage image = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & image ) ;
if ( NULL ! = image )
{
if ( HGBASE_ERR_OK = = HGImgProc_ImageAdjustColors ( image , image , brightness , contrast , ( HGFloat ) gamma ) )
{
if ( 0 = = SaveImage ( image , temp , outImagePath ) )
{
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
errInfo . clear ( ) ;
ret = 0 ;
}
}
HGBase_DestroyImage ( image ) ;
}
return ret ;
}
int ManagerV2 : : LocalImageBinarization ( const std : : string & imagePath , bool temp , std : : string & outImagePath , std : : string & errInfo )
{
outImagePath . clear ( ) ;
errInfo = " 错误 " ;
if ( imagePath . empty ( ) )
return - 1 ;
int ret = - 1 ;
HGImage image = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , 0 , NULL , 0 , HGBASE_IMGORIGIN_TOP , & image ) ;
if ( NULL ! = image )
{
if ( HGBASE_ERR_OK = = HGImgProc_ImageBinarization ( image , image , HGIMGPROC_THRESHTYPE_ADAPTIVE_MEAN , 120 , 51 , 41 ) )
{
if ( 0 = = SaveImage ( image , temp , outImagePath ) )
{
if ( ! temp )
{
m_saveFilePathList . push_back ( outImagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
errInfo . clear ( ) ;
ret = 0 ;
}
}
HGBase_DestroyImage ( image ) ;
}
return ret ;
}
2024-04-18 03:04:35 +00:00
int ManagerV2 : : InitDevice ( const std : : string & iden , bool haveIden , std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-05-30 11:01:23 +00:00
if ( m_initDevice )
2023-09-06 03:11:34 +00:00
{
errInfo = " 已初始化 " ;
2022-05-30 11:01:23 +00:00
return - 1 ;
2023-09-06 03:11:34 +00:00
}
2022-05-30 11:01:23 +00:00
2024-04-18 03:04:35 +00:00
m_initIden = iden ;
m_initHaveIden = haveIden ;
2022-05-30 11:01:23 +00:00
SANE_Int version_code = 0 ;
2022-06-07 03:18:55 +00:00
if ( SANE_STATUS_GOOD ! = sane_init_ex ( & version_code , sane_ex_callback , this ) )
{
2024-04-18 03:04:35 +00:00
m_initIden . clear ( ) ;
m_initHaveIden = false ;
2023-09-06 03:11:34 +00:00
errInfo = " 初始化失败 " ;
2022-06-07 03:18:55 +00:00
return - 1 ;
}
2022-06-01 10:36:22 +00:00
2022-05-30 11:01:23 +00:00
m_initDevice = true ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-30 11:01:23 +00:00
return 0 ;
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : DeinitDevice ( std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
2022-06-07 03:18:55 +00:00
errInfo = " 错误 " ;
if ( ! m_initDevice )
2023-09-06 03:11:34 +00:00
{
errInfo = " 还未初始化 " ;
2022-06-07 03:18:55 +00:00
return - 1 ;
2023-09-06 03:11:34 +00:00
}
2022-06-07 03:18:55 +00:00
std : : string errInfo2 ;
CloseDevice ( errInfo2 ) ;
sane_exit ( ) ;
m_initDevice = false ;
2022-05-30 11:01:23 +00:00
2024-04-18 03:04:35 +00:00
m_initIden . clear ( ) ;
m_initHaveIden = false ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-30 11:01:23 +00:00
return 0 ;
}
2022-06-07 03:18:55 +00:00
bool ManagerV2 : : IsDeviceInit ( )
{
return m_initDevice ;
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : GetDeviceNameList ( std : : vector < std : : string > & deviceNameList , std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
deviceNameList . clear ( ) ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-05-30 11:01:23 +00:00
if ( ! m_initDevice )
2023-09-06 03:11:34 +00:00
{
errInfo = " 还未初始化 " ;
2022-05-30 11:01:23 +00:00
return - 1 ;
2023-09-06 03:11:34 +00:00
}
2022-05-30 11:01:23 +00:00
2024-04-23 09:50:11 +00:00
const SANE_Device * * device = NULL ;
sane_get_devices ( & device , SANE_TRUE ) ;
if ( NULL = = device )
{
errInfo . clear ( ) ;
return 0 ;
}
const SANE_Device * * p = device ;
while ( NULL ! = * p )
{
deviceNameList . push_back ( ( * p ) - > name ) ;
+ + p ;
}
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-30 11:01:23 +00:00
return 0 ;
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : OpenDevice ( const std : : string & deviceName , std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2023-09-06 03:11:34 +00:00
if ( ! m_initDevice )
{
errInfo = " 还未初始化 " ;
2022-05-30 11:01:23 +00:00
return - 1 ;
2023-09-06 03:11:34 +00:00
}
if ( m_openDevice )
{
errInfo = " 已打开设备 " ;
return - 1 ;
}
2022-05-30 11:01:23 +00:00
SANE_Handle dev = NULL ;
2022-06-06 10:51:34 +00:00
SANE_Status status = sane_open ( deviceName . c_str ( ) , & dev ) ;
2022-05-30 11:01:23 +00:00
if ( SANE_STATUS_GOOD ! = status )
2023-09-06 03:11:34 +00:00
{
errInfo = Utf8ToStdString ( sane_strstatus ( status ) ) ;
2022-05-30 11:01:23 +00:00
return - 1 ;
2023-09-06 03:11:34 +00:00
}
2022-05-30 11:01:23 +00:00
2022-06-15 11:07:55 +00:00
// 从配置文件加载devParams
std : : vector < DeviceParam > devParams ;
LoadDeviceParams ( deviceName , devParams ) ;
// 设置devParams到设备
SetParamsToDevice ( dev , devParams ) ;
// 从设备获取到m_devParams
if ( 0 = = GetParamsFromDevice ( dev , m_devParams ) )
2022-06-09 09:30:04 +00:00
{
// 保存到配置文件
2022-06-15 11:07:55 +00:00
RestoreDeviceParams ( deviceName , m_devParams ) ;
2022-06-09 09:30:04 +00:00
}
2022-06-06 10:51:34 +00:00
2022-05-30 11:01:23 +00:00
m_devHandle = dev ;
2022-06-06 10:51:34 +00:00
m_devName = deviceName ;
2022-05-30 11:01:23 +00:00
m_openDevice = true ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2024-01-12 01:16:53 +00:00
std : : string snError ;
GetDeviceSN ( m_sn , snError ) ;
2022-05-30 11:01:23 +00:00
return 0 ;
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : CloseDevice ( std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
2022-06-07 03:18:55 +00:00
errInfo = " 错误 " ;
2022-06-01 10:55:54 +00:00
2022-06-07 03:18:55 +00:00
if ( ! m_openDevice )
2023-09-06 03:11:34 +00:00
{
errInfo = " 还未打开设备 " ;
2022-06-07 03:18:55 +00:00
return - 1 ;
2023-09-06 03:11:34 +00:00
}
2022-06-07 03:18:55 +00:00
std : : string errInfo2 ;
StopScan ( errInfo2 ) ;
sane_close ( m_devHandle ) ;
m_devHandle = NULL ;
m_devName . clear ( ) ;
2022-06-15 11:07:55 +00:00
m_devParams . clear ( ) ;
2022-06-07 03:18:55 +00:00
m_openDevice = false ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2024-01-12 01:16:53 +00:00
m_sn . clear ( ) ;
2022-05-30 11:01:23 +00:00
return 0 ;
}
2023-09-06 03:11:34 +00:00
int ManagerV2 : : GetDeviceSN ( std : : string & sn , std : : string & errInfo )
{
errInfo = " 错误 " ;
sn . clear ( ) ;
if ( ! m_openDevice )
{
errInfo = " 还未打开设备 " ;
return - 1 ;
}
char v [ 256 ] = { 0 } ;
SANE_Status status = sane_control_option ( m_devHandle , ( SANE_Int ) 0x8856 , SANE_ACTION_GET_VALUE , v , NULL ) ;
if ( SANE_STATUS_GOOD ! = status )
{
errInfo = Utf8ToStdString ( sane_strstatus ( status ) ) ;
return - 1 ;
}
sn = v ;
errInfo . clear ( ) ;
return 0 ;
}
2024-01-05 01:38:30 +00:00
int ManagerV2 : : GetDeviceFWVersion ( std : : string & fwVer , std : : string & errInfo )
{
errInfo = " 错误 " ;
fwVer . clear ( ) ;
if ( ! m_openDevice )
{
errInfo = " 还未打开设备 " ;
return - 1 ;
}
char v [ 256 ] = { 0 } ;
SANE_Status status = sane_control_option ( m_devHandle , ( SANE_Int ) 0x8857 , SANE_ACTION_GET_VALUE , v , NULL ) ;
if ( SANE_STATUS_GOOD ! = status )
{
errInfo = Utf8ToStdString ( sane_strstatus ( status ) ) ;
return - 1 ;
}
fwVer = v ;
errInfo . clear ( ) ;
return 0 ;
}
2022-06-15 11:07:55 +00:00
int ManagerV2 : : SetDeviceParam ( const std : : vector < DeviceParam > & devParams , std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2023-09-06 03:11:34 +00:00
if ( ! m_openDevice )
{
errInfo = " 还未打开设备 " ;
2022-05-30 11:01:23 +00:00
return - 1 ;
2023-09-06 03:11:34 +00:00
}
if ( m_scanning )
{
errInfo = " 已启动扫描 " ;
return - 1 ;
}
2022-05-30 11:01:23 +00:00
2022-06-15 11:07:55 +00:00
// 设置devParams到设备
int ret = SetParamsToDevice ( m_devHandle , devParams ) ;
// 从设备获取到m_devParams
if ( 0 = = GetParamsFromDevice ( m_devHandle , m_devParams ) )
2022-06-09 09:30:04 +00:00
{
// 保存到配置文件
2022-06-15 11:07:55 +00:00
RestoreDeviceParams ( m_devName , m_devParams ) ;
2022-06-09 09:30:04 +00:00
}
2022-06-06 10:51:34 +00:00
if ( 0 = = ret )
errInfo . clear ( ) ;
return ret ;
2022-05-30 11:01:23 +00:00
}
2022-06-16 06:20:52 +00:00
int ManagerV2 : : GetDeviceParam ( std : : vector < DeviceParamsGroup > & devParams , std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
2022-06-15 11:07:55 +00:00
devParams . clear ( ) ;
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2022-05-30 11:01:23 +00:00
2023-09-06 03:11:34 +00:00
if ( ! m_openDevice )
{
errInfo = " 还未打开设备 " ;
2022-05-30 11:01:23 +00:00
return - 1 ;
2023-09-06 03:11:34 +00:00
}
if ( m_devParams . empty ( ) )
{
errInfo = " 获取设备信息失败 " ;
return - 1 ;
}
2022-05-30 11:01:23 +00:00
2022-06-15 11:07:55 +00:00
devParams = m_devParams ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-30 11:01:23 +00:00
return 0 ;
}
2022-06-16 06:20:52 +00:00
int ManagerV2 : : ResetDeviceParam ( std : : string & errInfo )
{
errInfo = " 错误 " ;
2023-09-06 03:11:34 +00:00
if ( ! m_openDevice )
{
errInfo = " 还未打开设备 " ;
return - 1 ;
}
if ( m_scanning )
{
errInfo = " 已启动扫描 " ;
return - 1 ;
}
2022-06-16 06:20:52 +00:00
// 重置参数
int ret = ResetParamsToDevice ( m_devHandle ) ;
// 从设备获取到m_devParams
if ( 0 = = GetParamsFromDevice ( m_devHandle , m_devParams ) )
{
// 保存到配置文件
RestoreDeviceParams ( m_devName , m_devParams ) ;
}
if ( 0 = = ret )
errInfo . clear ( ) ;
return ret ;
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : GetCurrDeviceName ( std : : string & deviceName , std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
2022-06-07 03:18:55 +00:00
errInfo = " 错误 " ;
2023-09-06 03:11:34 +00:00
if ( ! m_openDevice )
{
errInfo = " 还未打开设备 " ;
return - 1 ;
}
2022-06-07 03:18:55 +00:00
2022-05-30 11:01:23 +00:00
deviceName = m_devName ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-30 11:01:23 +00:00
return 0 ;
}
2024-04-18 07:39:23 +00:00
int ManagerV2 : : StartScan ( class WSUser * user , const std : : string & iden , bool haveIden , bool blankCheck , bool localSave , bool getBase64 , std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
2022-06-06 10:51:34 +00:00
errInfo = " 错误 " ;
2023-09-06 03:11:34 +00:00
if ( ! m_openDevice )
{
errInfo = " 还未打开设备 " ;
return - 1 ;
}
if ( m_scanning )
{
errInfo = " 已启动扫描 " ;
return - 1 ;
}
2022-05-30 11:01:23 +00:00
2024-04-18 07:39:23 +00:00
m_scanUser = user ;
2024-04-18 03:04:35 +00:00
m_scanIden = iden ;
m_scanHaveIden = haveIden ;
2022-08-01 07:58:12 +00:00
m_scanBlankCheck = blankCheck ;
2024-04-18 03:04:35 +00:00
m_scanLocalSave = localSave ;
m_scanGetBase64 = getBase64 ;
2022-06-07 03:18:55 +00:00
HGBase_CreateEvent ( HGFALSE , HGFALSE , & m_scanEvent ) ;
assert ( NULL ! = m_scanEvent ) ;
2023-11-14 04:38:12 +00:00
m_dpi = GetDpi ( ) ;
2022-06-07 03:18:55 +00:00
2022-05-30 11:01:23 +00:00
SANE_Status status = sane_start ( m_devHandle ) ;
if ( SANE_STATUS_GOOD ! = status )
2022-06-07 03:18:55 +00:00
{
2023-09-06 03:11:34 +00:00
errInfo = Utf8ToStdString ( sane_strstatus ( status ) ) ;
2022-06-07 03:18:55 +00:00
HGBase_DestroyEvent ( m_scanEvent ) ;
m_scanEvent = NULL ;
2024-04-18 07:39:23 +00:00
m_scanUser = NULL ;
2024-04-18 03:04:35 +00:00
m_scanIden . clear ( ) ;
m_scanHaveIden = false ;
2022-08-01 07:58:12 +00:00
m_scanBlankCheck = false ;
2024-04-18 03:04:35 +00:00
m_scanLocalSave = true ;
m_scanGetBase64 = false ;
2023-11-14 04:38:12 +00:00
m_dpi = 200 ;
2022-05-30 11:01:23 +00:00
return - 1 ;
2022-06-07 03:18:55 +00:00
}
2022-05-30 11:01:23 +00:00
m_scanning = true ;
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2024-04-23 09:50:11 +00:00
HGTimeInfo timeInfo ;
HGBase_GetLocalTime ( & timeInfo ) ;
char filePath [ 256 ] = { 0 } ;
sprintf ( filePath , " %04d-%02d-%02d-%02d.%02d.%02d " , timeInfo . year , timeInfo . month , timeInfo . day , timeInfo . hour , timeInfo . minute , timeInfo . second ) ;
m_curBatchTime = filePath ;
2022-05-30 11:01:23 +00:00
return 0 ;
}
2022-06-06 10:51:34 +00:00
int ManagerV2 : : StopScan ( std : : string & errInfo )
2022-05-30 11:01:23 +00:00
{
2022-06-07 03:18:55 +00:00
errInfo = " 错误 " ;
2022-06-01 10:36:22 +00:00
2023-09-06 03:11:34 +00:00
if ( ! m_scanning )
{
errInfo = " 还未启动扫描 " ;
return - 1 ;
}
2022-06-07 03:18:55 +00:00
assert ( NULL ! = m_devHandle ) ;
sane_cancel ( m_devHandle ) ;
assert ( NULL ! = m_scanEvent ) ;
HGBase_WaitEvent ( m_scanEvent ) ;
HGBase_DestroyEvent ( m_scanEvent ) ;
m_scanEvent = NULL ;
2024-04-18 07:39:23 +00:00
m_scanUser = NULL ;
2024-04-18 03:04:35 +00:00
m_scanIden . clear ( ) ;
m_scanHaveIden = false ;
2022-08-01 07:58:12 +00:00
m_scanBlankCheck = false ;
2024-04-18 03:04:35 +00:00
m_scanLocalSave = true ;
m_scanGetBase64 = false ;
2022-06-07 03:18:55 +00:00
m_scanning = false ;
2023-11-14 04:38:12 +00:00
m_dpi = 200 ;
2024-04-23 09:50:11 +00:00
m_curBatchTime . clear ( ) ;
m_curImgIndex = 0 ;
2022-05-30 11:01:23 +00:00
2022-06-06 10:51:34 +00:00
errInfo . clear ( ) ;
2022-05-30 11:01:23 +00:00
return 0 ;
}
2022-06-07 03:18:55 +00:00
bool ManagerV2 : : IsScanning ( )
{
return m_scanning ;
}
int ManagerV2 : : GetBatchIdList ( std : : vector < std : : string > & batchIdList , std : : string & errInfo )
{
2022-06-07 10:22:27 +00:00
batchIdList . clear ( ) ;
errInfo = " 错误 " ;
if ( NULL = = m_sqlite )
return - 1 ;
2022-06-16 09:52:10 +00:00
sqlite3_stmt * stmt = NULL ;
2022-06-22 07:41:59 +00:00
int ret = sqlite3_prepare ( m_sqlite , " select name from table_ order by id asc " , - 1 , & stmt , NULL ) ;
2022-06-16 09:52:10 +00:00
assert ( 0 = = ret ) ;
2022-06-07 10:22:27 +00:00
2022-06-16 09:52:10 +00:00
ret = sqlite3_step ( stmt ) ;
while ( SQLITE_ROW = = ret )
2022-06-07 10:22:27 +00:00
{
2022-06-22 07:41:59 +00:00
const char * name = ( const char * ) sqlite3_column_text ( stmt , 0 ) ;
batchIdList . push_back ( name ) ;
2022-06-16 09:52:10 +00:00
ret = sqlite3_step ( stmt ) ;
2022-06-07 10:22:27 +00:00
}
2022-06-16 09:52:10 +00:00
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
2022-06-07 10:22:27 +00:00
errInfo . clear ( ) ;
return 0 ;
2022-06-07 03:18:55 +00:00
}
int ManagerV2 : : OpenBatch ( const std : : string & batchId , std : : string & errInfo )
{
2022-06-07 10:22:27 +00:00
errInfo = " 错误 " ;
if ( batchId . empty ( ) )
return - 1 ;
std : : vector < std : : string > batchIdList ;
std : : string errInfo2 ;
GetBatchIdList ( batchIdList , errInfo2 ) ;
int ret = - 1 ;
for ( int i = 0 ; i < ( int ) batchIdList . size ( ) ; + + i )
{
if ( batchId = = batchIdList [ i ] )
{
2022-06-11 06:18:33 +00:00
if ( m_currBatchId ! = batchId )
{
m_currBatchId = batchId ;
if ( ! m_bindFolder . empty ( ) )
{
2022-06-13 04:02:51 +00:00
ClearBindFolder ( ) ;
2022-06-11 06:18:33 +00:00
UpdateBindFolder ( ) ;
}
}
2022-06-07 10:22:27 +00:00
errInfo . clear ( ) ;
ret = 0 ;
break ;
}
}
return ret ;
2022-06-07 03:18:55 +00:00
}
int ManagerV2 : : DeleteBatch ( const std : : string & batchId , std : : string & errInfo )
{
2022-06-07 10:22:27 +00:00
errInfo = " 错误 " ;
if ( batchId . empty ( ) | | batchId = = m_currBatchId )
return - 1 ;
if ( NULL = = m_sqlite )
return - 1 ;
char sql [ 256 ] ;
2022-06-22 07:41:59 +00:00
int ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-22 12:38:39 +00:00
sprintf ( sql , " drop table 'table_%s_idx' " , batchId . c_str ( ) ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
2022-06-07 10:22:27 +00:00
sprintf ( sql , " drop table 'table_%s' " , batchId . c_str ( ) ) ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-07 10:22:27 +00:00
if ( 0 ! = ret )
2022-06-22 07:41:59 +00:00
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-07 10:22:27 +00:00
return - 1 ;
2022-06-22 07:41:59 +00:00
}
2022-06-07 10:22:27 +00:00
sprintf ( sql , " delete from table_ where name = '%s' " , batchId . c_str ( ) ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
2022-06-07 10:22:27 +00:00
assert ( 0 = = ret ) ;
errInfo . clear ( ) ;
return 0 ;
2022-06-07 03:18:55 +00:00
}
2022-06-07 10:22:27 +00:00
int ManagerV2 : : NewBatch ( const std : : string & batchId , std : : string & errInfo )
2022-06-07 03:18:55 +00:00
{
2022-06-07 10:22:27 +00:00
errInfo = " 错误 " ;
if ( batchId . empty ( ) )
return - 1 ;
if ( NULL = = m_sqlite )
return - 1 ;
char sql [ 256 ] ;
2022-06-22 07:41:59 +00:00
int ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-22 12:38:39 +00:00
sprintf ( sql , " create table 'table_%s' (id integer primary key autoincrement, format text, tag text, image blob, thumb blob) " , batchId . c_str ( ) ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
sprintf ( sql , " create table 'table_%s_idx' (id integer, idx integer) " , batchId . c_str ( ) ) ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-07 10:22:27 +00:00
if ( 0 ! = ret )
2022-06-22 07:41:59 +00:00
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-07 10:22:27 +00:00
return - 1 ;
2022-06-22 07:41:59 +00:00
}
2022-06-07 10:22:27 +00:00
sprintf ( sql , " insert into table_ (name) values ('%s') " , batchId . c_str ( ) ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
2022-06-07 10:22:27 +00:00
assert ( 0 = = ret ) ;
m_currBatchId = batchId ;
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-13 04:02:51 +00:00
ClearBindFolder ( ) ;
2022-06-11 06:18:33 +00:00
UpdateBindFolder ( ) ;
}
2022-06-07 10:22:27 +00:00
errInfo . clear ( ) ;
return 0 ;
2022-06-07 03:18:55 +00:00
}
int ManagerV2 : : GetCurrBatchId ( std : : string & batchId , std : : string & errInfo )
{
2022-06-07 10:22:27 +00:00
batchId . clear ( ) ;
errInfo = " 错误 " ;
if ( NULL = = m_sqlite )
return - 1 ;
batchId = m_currBatchId ;
errInfo . clear ( ) ;
return 0 ;
2022-06-07 03:18:55 +00:00
}
int ManagerV2 : : ModifyBatchId ( const std : : string & batchId , const std : : string & newBatchId , std : : string & errInfo )
{
2022-06-07 10:22:27 +00:00
errInfo = " 错误 " ;
if ( batchId . empty ( ) | | newBatchId . empty ( ) )
return - 1 ;
if ( NULL = = m_sqlite )
return - 1 ;
char sql [ 256 ] ;
2022-06-22 07:41:59 +00:00
int ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-07 10:22:27 +00:00
sprintf ( sql , " alter table 'table_%s' rename to 'table_%s' " , batchId . c_str ( ) , newBatchId . c_str ( ) ) ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-07 10:22:27 +00:00
if ( 0 ! = ret )
2022-06-22 07:41:59 +00:00
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-07 10:22:27 +00:00
return - 1 ;
2022-06-22 07:41:59 +00:00
}
2022-06-07 10:22:27 +00:00
2022-06-22 12:38:39 +00:00
sprintf ( sql , " alter table 'table_%s_idx' rename to 'table_%s_idx' " , batchId . c_str ( ) , newBatchId . c_str ( ) ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
2022-06-07 10:22:27 +00:00
sprintf ( sql , " update table_ set name = '%s' where name = '%s' " , newBatchId . c_str ( ) , batchId . c_str ( ) ) ;
2022-06-08 10:54:34 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
2022-06-07 10:22:27 +00:00
assert ( 0 = = ret ) ;
if ( batchId = = m_currBatchId )
m_currBatchId = newBatchId ;
errInfo . clear ( ) ;
return 0 ;
2022-06-07 03:18:55 +00:00
}
2022-06-13 04:02:51 +00:00
int ManagerV2 : : BindFolder ( const std : : string & folder , const std : : string & nameMode , int nameWidth , int nameBase , std : : string & errInfo )
2022-06-11 06:18:33 +00:00
{
errInfo = " 错误 " ;
if ( folder . empty ( ) )
return - 1 ;
2022-06-13 04:02:51 +00:00
if ( " order " ! = nameMode | | nameWidth < = 0 | | nameBase < 0 )
2022-06-11 06:18:33 +00:00
return - 1 ;
// 需要保证文件夹为空??
if ( NULL = = m_sqlite )
return - 1 ;
m_bindFolder = folder ;
m_bindFolder . push_back ( ' / ' ) ;
HGChar stdBindFolder [ 256 ] ;
HGBase_StandardiseFileName ( m_bindFolder . c_str ( ) , stdBindFolder , 256 ) ;
m_bindFolder = stdBindFolder ;
m_bindNameMode = nameMode ;
2022-06-13 04:02:51 +00:00
m_bindNameWidth = nameWidth ;
m_bindNameBase = nameBase ;
2022-06-11 06:18:33 +00:00
2022-06-13 04:02:51 +00:00
ClearBindFolder ( ) ;
2022-06-11 06:18:33 +00:00
UpdateBindFolder ( ) ;
errInfo . clear ( ) ;
return 0 ;
}
int ManagerV2 : : StopBindFolder ( std : : string & errInfo )
{
errInfo = " 错误 " ;
if ( NULL = = m_sqlite )
return - 1 ;
m_bindFolder . clear ( ) ;
m_bindNameMode . clear ( ) ;
2022-06-13 04:02:51 +00:00
m_bindNameWidth = 0 ;
m_bindNameBase = 0 ;
2022-06-11 06:18:33 +00:00
errInfo . clear ( ) ;
return 0 ;
}
2022-06-09 09:30:04 +00:00
int ManagerV2 : : GetImageThumbnailList ( std : : vector < ImageThumbInfo > & imageThumbList , std : : string & errInfo )
{
imageThumbList . clear ( ) ;
errInfo = " 错误 " ;
if ( NULL = = m_sqlite )
return - 1 ;
int rc = - 1 ;
sqlite3_stmt * stmt = NULL ;
char sql [ 256 ] ;
2022-07-05 02:36:01 +00:00
sprintf ( sql , " select format, tag, thumb from table_%s join table_%s_idx on table_%s.id == table_%s_idx.id order by table_%s_idx.idx asc " ,
2022-06-22 12:38:39 +00:00
m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) ) ;
2022-06-09 09:30:04 +00:00
int ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_step ( stmt ) ;
while ( SQLITE_ROW = = ret )
{
2022-06-22 07:41:59 +00:00
ImageThumbInfo thumbInfo ;
imageThumbList . push_back ( thumbInfo ) ;
ImageThumbInfo & thumbInfoEx = imageThumbList [ imageThumbList . size ( ) - 1 ] ;
2022-06-09 09:30:04 +00:00
2022-06-22 07:41:59 +00:00
std : : string imgFmt = ( const char * ) sqlite3_column_text ( stmt , 0 ) ;
std : : string imgTag = ( const char * ) sqlite3_column_text ( stmt , 1 ) ;
const void * thumbData = sqlite3_column_blob ( stmt , 2 ) ;
int thumbSize = sqlite3_column_bytes ( stmt , 2 ) ;
thumbInfoEx . tag = imgTag ;
SaveToBase64 ( ( const HGByte * ) thumbData , thumbSize , thumbInfoEx . thumbBase64 ) ;
assert ( ! thumbInfoEx . thumbBase64 . empty ( ) ) ;
2022-06-09 09:30:04 +00:00
std : : string prefix ;
if ( " jpg " = = imgFmt )
prefix = " data:image/jpeg;base64, " ;
else if ( " bmp " = = imgFmt )
prefix = " data:image/bmp;base64, " ;
else if ( " png " = = imgFmt )
prefix = " data:image/png;base64, " ;
else if ( " tif " = = imgFmt )
prefix = " data:image/tiff;base64, " ;
else if ( " pdf " = = imgFmt )
prefix = " data:image/pdf;base64, " ;
else if ( " ofd " = = imgFmt )
prefix = " data:image/ofd;base64, " ;
2022-06-22 07:41:59 +00:00
thumbInfoEx . thumbBase64 . insert ( 0 , prefix ) ;
2022-06-09 09:30:04 +00:00
ret = sqlite3_step ( stmt ) ;
}
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
errInfo . clear ( ) ;
return 0 ;
}
2022-06-07 03:18:55 +00:00
int ManagerV2 : : GetImageCount ( int & imageCount , std : : string & errInfo )
{
2022-06-08 10:54:34 +00:00
imageCount = 0 ;
errInfo = " 错误 " ;
2022-06-07 03:18:55 +00:00
2022-06-08 10:54:34 +00:00
if ( NULL = = m_sqlite )
return - 1 ;
2022-06-07 03:18:55 +00:00
2022-06-08 10:54:34 +00:00
char * * result = NULL ;
char sql [ 256 ] ;
2022-06-22 12:38:39 +00:00
sprintf ( sql , " select id from 'table_%s_idx' " , m_currBatchId . c_str ( ) ) ;
2022-06-08 10:54:34 +00:00
int rows , cols ;
int ret = sqlite3_get_table ( m_sqlite , sql , & result , & rows , & cols , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-07 03:18:55 +00:00
2022-06-08 10:54:34 +00:00
imageCount = rows ;
sqlite3_free_table ( result ) ;
2022-06-07 03:18:55 +00:00
2022-06-08 10:54:34 +00:00
errInfo . clear ( ) ;
return 0 ;
2022-06-07 03:18:55 +00:00
}
2022-06-08 10:54:34 +00:00
int ManagerV2 : : LoadImage ( int imageIndex , std : : string & imageTag , std : : string & imageBase64 , std : : string & errInfo )
2022-06-07 03:18:55 +00:00
{
2022-06-08 10:54:34 +00:00
imageTag . clear ( ) ;
imageBase64 . clear ( ) ;
errInfo = " 错误 " ;
2022-06-07 03:18:55 +00:00
2022-06-08 10:54:34 +00:00
if ( NULL = = m_sqlite )
return - 1 ;
2022-06-07 03:18:55 +00:00
2022-06-22 12:38:39 +00:00
int id = GetId ( imageIndex ) ;
if ( - 1 = = id )
return - 1 ;
2022-06-08 10:54:34 +00:00
int rc = - 1 ;
2022-06-07 03:18:55 +00:00
2022-06-08 10:54:34 +00:00
sqlite3_stmt * stmt = NULL ;
char sql [ 256 ] ;
2022-06-22 12:38:39 +00:00
sprintf ( sql , " select format, tag, image from 'table_%s' where id = '%d' " , m_currBatchId . c_str ( ) , id ) ;
2022-06-08 10:54:34 +00:00
int ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_step ( stmt ) ;
2022-06-22 07:41:59 +00:00
if ( SQLITE_ROW = = ret )
{
std : : string imgFmt = ( const char * ) sqlite3_column_text ( stmt , 0 ) ;
std : : string imgTag = ( const char * ) sqlite3_column_text ( stmt , 1 ) ;
const void * imgData = sqlite3_column_blob ( stmt , 2 ) ;
int imgSize = sqlite3_column_bytes ( stmt , 2 ) ;
if ( SaveToBase64 ( ( const HGByte * ) imgData , imgSize , imageBase64 ) )
{
imageTag = imgTag ;
std : : string prefix ;
if ( " jpg " = = imgFmt )
prefix = " data:image/jpeg;base64, " ;
else if ( " bmp " = = imgFmt )
prefix = " data:image/bmp;base64, " ;
else if ( " png " = = imgFmt )
prefix = " data:image/png;base64, " ;
else if ( " tif " = = imgFmt )
prefix = " data:image/tiff;base64, " ;
else if ( " pdf " = = imgFmt )
prefix = " data:image/pdf;base64, " ;
else if ( " ofd " = = imgFmt )
prefix = " data:image/ofd;base64, " ;
imageBase64 . insert ( 0 , prefix ) ;
2022-06-07 03:18:55 +00:00
2022-06-22 07:41:59 +00:00
errInfo . clear ( ) ;
rc = 0 ;
2022-06-08 10:54:34 +00:00
}
}
2022-05-23 10:29:23 +00:00
2022-06-08 10:54:34 +00:00
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
return rc ;
2022-05-23 10:29:23 +00:00
}
2022-06-22 07:41:59 +00:00
int ManagerV2 : : SaveImage ( int imageIndex , bool temp , std : : string & imagePath , std : : string & errInfo )
2022-05-23 10:29:23 +00:00
{
2022-06-08 10:54:34 +00:00
imagePath . clear ( ) ;
errInfo = " 错误 " ;
2022-05-23 10:29:23 +00:00
2022-06-08 10:54:34 +00:00
if ( NULL = = m_sqlite )
return - 1 ;
2022-06-06 10:51:34 +00:00
2022-06-22 12:38:39 +00:00
int id = GetId ( imageIndex ) ;
if ( - 1 = = id )
return - 1 ;
2022-06-08 10:54:34 +00:00
int rc = - 1 ;
2022-06-06 10:51:34 +00:00
2022-06-08 10:54:34 +00:00
sqlite3_stmt * stmt = NULL ;
char sql [ 256 ] ;
2022-06-22 12:38:39 +00:00
sprintf ( sql , " select format, image from 'table_%s' where id = '%d' " , m_currBatchId . c_str ( ) , id ) ;
2022-06-08 10:54:34 +00:00
int ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_step ( stmt ) ;
2022-06-22 07:41:59 +00:00
if ( SQLITE_ROW = = ret )
2022-06-08 10:54:34 +00:00
{
2022-06-22 07:41:59 +00:00
std : : string imgFmt = ( const char * ) sqlite3_column_text ( stmt , 0 ) ;
const void * imgData = sqlite3_column_blob ( stmt , 1 ) ;
int imgSize = sqlite3_column_bytes ( stmt , 1 ) ;
2022-06-08 10:54:34 +00:00
2022-06-22 07:41:59 +00:00
std : : string imagePath2 = GetFilePath ( temp , imgFmt . c_str ( ) ) ;
if ( SaveToFile ( ( const HGByte * ) imgData , imgSize , imagePath2 ) )
{
imagePath = imagePath2 ;
if ( ! temp )
2022-06-08 10:54:34 +00:00
{
m_saveFilePathList . push_back ( imagePath ) ;
RestoreSaveFilePathList ( m_saveFilePathList ) ;
}
2022-05-23 10:29:23 +00:00
2022-06-22 07:41:59 +00:00
errInfo . clear ( ) ;
rc = 0 ;
2022-06-08 10:54:34 +00:00
}
}
2022-05-23 10:29:23 +00:00
2022-06-08 10:54:34 +00:00
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
return rc ;
2022-05-23 10:29:23 +00:00
}
2022-06-08 10:54:34 +00:00
int ManagerV2 : : InsertLocalImage ( const std : : string & imagePath , int insertPos , const std : : string & imageTag , std : : string & errInfo )
2022-06-06 10:51:34 +00:00
{
2022-06-08 10:54:34 +00:00
errInfo = " 错误 " ;
2022-06-06 10:51:34 +00:00
2022-06-08 10:54:34 +00:00
if ( NULL = = m_sqlite | | imagePath . empty ( ) | | insertPos < - 1 )
return - 1 ;
2022-06-06 10:51:34 +00:00
2022-06-08 10:54:34 +00:00
HGUInt imgSize = 0 ;
2022-06-09 09:30:04 +00:00
std : : string imgFormat ;
HGByte * imgData = LoadImageFromPath ( imagePath . c_str ( ) , imgSize , imgFormat ) ;
if ( NULL = = imgData )
return - 1 ;
2022-05-23 10:29:23 +00:00
2022-06-09 09:30:04 +00:00
HGUInt thumbSize = 0 ;
HGByte * thumbData = LoadThumbFromPath ( imagePath . c_str ( ) , thumbSize ) ;
if ( NULL = = thumbData )
2022-05-23 10:29:23 +00:00
{
2022-06-09 09:30:04 +00:00
delete [ ] imgData ;
2022-05-23 10:29:23 +00:00
return - 1 ;
2022-06-09 09:30:04 +00:00
}
2022-05-23 10:29:23 +00:00
2022-06-11 06:18:33 +00:00
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-08 10:54:34 +00:00
2022-06-22 07:41:59 +00:00
if ( - 1 = = insertPos )
insertPos = ( int ) tables . size ( ) ;
else if ( insertPos > ( int ) tables . size ( ) )
2022-06-08 10:54:34 +00:00
{
2022-06-22 07:41:59 +00:00
delete [ ] thumbData ;
delete [ ] imgData ;
return - 1 ;
2022-06-08 10:54:34 +00:00
}
2022-06-11 06:18:33 +00:00
int ret ;
char sql [ 1024 ] ;
2022-06-16 09:52:10 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-22 12:38:39 +00:00
do
2022-06-08 10:54:34 +00:00
{
2022-06-22 12:38:39 +00:00
sprintf ( sql , " insert into 'table_%s' (format, tag, image, thumb) values ('%s', '%s', ?, ?) " , m_currBatchId . c_str ( ) ,
imgFormat . c_str ( ) , imageTag . c_str ( ) ) ;
sqlite3_stmt * stmt = NULL ;
ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_bind_blob ( stmt , 1 , imgData , ( int ) imgSize , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_bind_blob ( stmt , 2 , thumbData , ( int ) thumbSize , NULL ) ;
assert ( 0 = = ret ) ;
sqlite3_step ( stmt ) ;
ret = sqlite3_finalize ( stmt ) ;
if ( 0 ! = ret )
2022-06-08 10:54:34 +00:00
{
2022-06-22 12:38:39 +00:00
break ;
}
bool ok = true ;
for ( int i = 0 ; i < ( int ) tables . size ( ) ; + + i )
{
if ( i > = insertPos )
2022-06-16 09:52:10 +00:00
{
2022-06-22 12:38:39 +00:00
sprintf ( sql , " update 'table_%s_idx' set idx = '%d' where id = '%d' " ,
m_currBatchId . c_str ( ) , i + 1 , tables [ i ] . id ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
ok = false ;
break ;
}
2022-06-16 09:52:10 +00:00
}
2022-06-08 10:54:34 +00:00
}
2022-06-22 12:38:39 +00:00
if ( ! ok )
{
break ;
}
int id = ( int ) sqlite3_last_insert_rowid ( m_sqlite ) ;
sprintf ( sql , " insert into 'table_%s_idx' (id, idx) values ('%d', '%d') " , m_currBatchId . c_str ( ) ,
id , insertPos ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
break ;
}
} while ( 0 ) ;
2022-06-16 09:52:10 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
delete [ ] thumbData ;
delete [ ] imgData ;
return - 1 ;
}
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
2022-06-08 10:54:34 +00:00
assert ( 0 = = ret ) ;
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-11 09:54:04 +00:00
InsertBindFolderImage ( tables , insertPos , imgFormat , imgData , imgSize ) ;
2022-06-11 06:18:33 +00:00
}
2022-06-09 09:30:04 +00:00
delete [ ] thumbData ;
2022-06-08 10:54:34 +00:00
delete [ ] imgData ;
errInfo . clear ( ) ;
return 0 ;
}
int ManagerV2 : : InsertImage ( const std : : string & imageBase64 , int insertPos , const std : : string & imageTag , std : : string & errInfo )
{
errInfo = " 错误 " ;
if ( NULL = = m_sqlite | | imageBase64 . empty ( ) | | insertPos < - 1 )
return - 1 ;
2022-06-09 09:30:04 +00:00
HGUInt imgSize = 0 ;
std : : string imgFormat ;
HGByte * imgData = LoadImageFromBase64 ( imageBase64 . c_str ( ) , imgSize , imgFormat ) ;
if ( NULL = = imgData )
2022-06-08 10:54:34 +00:00
return - 1 ;
2022-06-09 09:30:04 +00:00
HGUInt thumbSize = 0 ;
HGByte * thumbData = LoadThumbFromBase64 ( imageBase64 . c_str ( ) , thumbSize ) ;
if ( NULL = = thumbData )
2022-06-08 10:54:34 +00:00
{
2022-06-09 09:30:04 +00:00
delete [ ] imgData ;
2022-06-08 10:54:34 +00:00
return - 1 ;
2022-06-09 09:30:04 +00:00
}
2022-06-08 10:54:34 +00:00
2022-06-11 06:18:33 +00:00
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-08 10:54:34 +00:00
2022-06-22 07:41:59 +00:00
if ( - 1 = = insertPos )
insertPos = ( int ) tables . size ( ) ;
else if ( insertPos > ( int ) tables . size ( ) )
2022-06-08 10:54:34 +00:00
{
2022-06-22 07:41:59 +00:00
delete [ ] thumbData ;
delete [ ] imgData ;
return - 1 ;
2022-06-08 10:54:34 +00:00
}
2022-06-11 06:18:33 +00:00
int ret ;
char sql [ 1024 ] ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-22 12:38:39 +00:00
do
2022-06-08 10:54:34 +00:00
{
2022-06-22 12:38:39 +00:00
sprintf ( sql , " insert into 'table_%s' (format, tag, image, thumb) values ('%s', '%s', ?, ?) " , m_currBatchId . c_str ( ) ,
imgFormat . c_str ( ) , imageTag . c_str ( ) ) ;
sqlite3_stmt * stmt = NULL ;
ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_bind_blob ( stmt , 1 , imgData , ( int ) imgSize , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_bind_blob ( stmt , 2 , thumbData , ( int ) thumbSize , NULL ) ;
assert ( 0 = = ret ) ;
sqlite3_step ( stmt ) ;
ret = sqlite3_finalize ( stmt ) ;
if ( 0 ! = ret )
2022-06-08 10:54:34 +00:00
{
2022-06-22 12:38:39 +00:00
break ;
}
bool ok = true ;
for ( int i = 0 ; i < ( int ) tables . size ( ) ; + + i )
{
if ( i > = insertPos )
2022-06-22 07:41:59 +00:00
{
2022-06-22 12:38:39 +00:00
sprintf ( sql , " update 'table_%s_idx' set idx = '%d' where id = '%d' " ,
m_currBatchId . c_str ( ) , i + 1 , tables [ i ] . id ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
ok = false ;
break ;
}
2022-06-22 07:41:59 +00:00
}
2022-06-08 10:54:34 +00:00
}
2022-06-22 12:38:39 +00:00
if ( ! ok )
{
break ;
}
int id = ( int ) sqlite3_last_insert_rowid ( m_sqlite ) ;
sprintf ( sql , " insert into 'table_%s_idx' (id, idx) values ('%d', '%d') " , m_currBatchId . c_str ( ) ,
id , insertPos ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
break ;
}
} while ( 0 ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
delete [ ] thumbData ;
delete [ ] imgData ;
return - 1 ;
}
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
2022-06-08 10:54:34 +00:00
assert ( 0 = = ret ) ;
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-11 09:54:04 +00:00
InsertBindFolderImage ( tables , insertPos , imgFormat , imgData , imgSize ) ;
2022-06-11 06:18:33 +00:00
}
2022-06-09 09:30:04 +00:00
delete [ ] thumbData ;
2022-06-08 10:54:34 +00:00
delete [ ] imgData ;
errInfo . clear ( ) ;
return 0 ;
}
int ManagerV2 : : ModifyImageTag ( const std : : vector < int > & imageIndexList , const std : : vector < std : : string > & imageTagList , std : : string & errInfo )
{
errInfo = " 错误 " ;
2022-06-09 09:51:07 +00:00
2022-06-08 10:54:34 +00:00
if ( NULL = = m_sqlite | | imageIndexList . empty ( ) | | imageTagList . empty ( )
| | imageIndexList . size ( ) ! = imageTagList . size ( ) )
return - 1 ;
2022-06-11 06:18:33 +00:00
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-08 10:54:34 +00:00
bool indexValid = true ;
for ( int i = 0 ; i < ( int ) imageIndexList . size ( ) ; + + i )
{
2022-06-22 07:41:59 +00:00
if ( imageIndexList [ i ] < 0 | | imageIndexList [ i ] > = ( int ) tables . size ( ) )
2022-06-08 10:54:34 +00:00
{
indexValid = false ;
break ;
}
}
if ( ! indexValid )
return - 1 ;
2022-06-11 06:18:33 +00:00
int ret ;
char sql [ 1024 ] ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
bool ok = true ;
2022-06-08 10:54:34 +00:00
for ( int i = 0 ; i < ( int ) imageIndexList . size ( ) ; + + i )
{
2022-06-22 12:38:39 +00:00
int id = tables [ imageIndexList [ i ] ] . id ;
sprintf ( sql , " update 'table_%s' set tag = '%s' where id = '%d' " ,
m_currBatchId . c_str ( ) , imageTagList [ i ] . c_str ( ) , id ) ;
2022-06-08 10:54:34 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ok = false ;
break ;
}
}
if ( ! ok )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
2022-06-08 10:54:34 +00:00
assert ( 0 = = ret ) ;
2022-06-22 07:41:59 +00:00
return - 1 ;
2022-06-08 10:54:34 +00:00
}
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-08 10:54:34 +00:00
errInfo . clear ( ) ;
return 0 ;
}
int ManagerV2 : : DeleteImage ( const std : : vector < int > & imageIndexList , std : : string & errInfo )
{
errInfo = " 错误 " ;
if ( NULL = = m_sqlite | | imageIndexList . empty ( ) )
return - 1 ;
2022-06-11 06:18:33 +00:00
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-08 10:54:34 +00:00
bool indexValid = true ;
for ( int i = 0 ; i < ( int ) imageIndexList . size ( ) ; + + i )
{
2022-06-22 07:41:59 +00:00
if ( imageIndexList [ i ] < 0 | | imageIndexList [ i ] > = ( int ) tables . size ( ) )
2022-06-08 10:54:34 +00:00
{
indexValid = false ;
break ;
}
}
if ( ! indexValid )
return - 1 ;
2022-06-11 06:18:33 +00:00
int ret ;
char sql [ 1024 ] ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
bool ok = true ;
2022-06-08 10:54:34 +00:00
for ( int i = 0 ; i < ( int ) imageIndexList . size ( ) ; + + i )
{
2022-06-22 12:38:39 +00:00
int id = tables [ imageIndexList [ i ] ] . id ;
sprintf ( sql , " delete from 'table_%s' where id = '%d' " , m_currBatchId . c_str ( ) , id ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
ok = false ;
break ;
}
sprintf ( sql , " delete from 'table_%s_idx' where id = '%d' " , m_currBatchId . c_str ( ) , id ) ;
2022-06-08 10:54:34 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ok = false ;
break ;
}
}
if ( ! ok )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
2022-06-08 10:54:34 +00:00
assert ( 0 = = ret ) ;
2022-06-22 07:41:59 +00:00
return - 1 ;
2022-06-08 10:54:34 +00:00
}
int value = 0 ;
for ( int i = 0 ; i < ( int ) tables . size ( ) ; + + i )
{
bool find = false ;
for ( int j = 0 ; j < ( int ) imageIndexList . size ( ) ; + + j )
{
2022-06-22 07:41:59 +00:00
if ( i = = imageIndexList [ j ] )
2022-06-08 10:54:34 +00:00
{
find = true ;
break ;
}
}
if ( find )
{
+ + value ;
}
else
{
if ( value > 0 )
{
2022-06-22 12:38:39 +00:00
sprintf ( sql , " update 'table_%s_idx' set idx = '%d' where id = '%d' " ,
2022-06-22 07:41:59 +00:00
m_currBatchId . c_str ( ) , i - value , tables [ i ] . id ) ;
2022-06-08 10:54:34 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ok = false ;
break ;
}
2022-06-08 10:54:34 +00:00
}
}
}
2022-06-22 07:41:59 +00:00
if ( ! ok )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-11 09:54:04 +00:00
DeleteBindFolderImage ( tables , imageIndexList ) ;
2022-06-11 06:18:33 +00:00
}
2022-06-08 10:54:34 +00:00
errInfo . clear ( ) ;
return 0 ;
}
int ManagerV2 : : ClearImageList ( std : : string & errInfo )
{
errInfo = " 错误 " ;
if ( NULL = = m_sqlite )
return - 1 ;
2022-06-13 04:02:51 +00:00
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-08 10:54:34 +00:00
char sql [ 256 ] ;
2022-06-22 07:41:59 +00:00
int ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-08 10:54:34 +00:00
sprintf ( sql , " delete from 'table_%s' " , m_currBatchId . c_str ( ) ) ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
2022-06-22 12:38:39 +00:00
sprintf ( sql , " delete from 'table_%s_idx' " , m_currBatchId . c_str ( ) ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
2022-06-08 10:54:34 +00:00
assert ( 0 = = ret ) ;
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-13 04:02:51 +00:00
ClearBindFolderImageList ( tables ) ;
2022-06-11 06:18:33 +00:00
}
2022-06-08 10:54:34 +00:00
errInfo . clear ( ) ;
return 0 ;
}
int ManagerV2 : : ModifyImage ( int imageIndex , const std : : string & imageBase64 , std : : string & errInfo )
{
errInfo = " 错误 " ;
if ( NULL = = m_sqlite | | imageIndex < 0 | | imageBase64 . empty ( ) )
return - 1 ;
2022-06-09 09:30:04 +00:00
HGUInt imgSize = 0 ;
std : : string imgFormat ;
HGByte * imgData = LoadImageFromBase64 ( imageBase64 . c_str ( ) , imgSize , imgFormat ) ;
if ( NULL = = imgData )
2022-06-08 10:54:34 +00:00
return - 1 ;
2022-06-09 09:30:04 +00:00
HGUInt thumbSize = 0 ;
HGByte * thumbData = LoadThumbFromBase64 ( imageBase64 . c_str ( ) , thumbSize ) ;
if ( NULL = = thumbData )
2022-06-08 10:54:34 +00:00
{
2022-06-09 09:30:04 +00:00
delete [ ] imgData ;
2022-06-08 10:54:34 +00:00
return - 1 ;
2022-06-09 09:30:04 +00:00
}
2022-06-08 10:54:34 +00:00
2022-06-11 06:18:33 +00:00
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-08 10:54:34 +00:00
2022-06-22 07:41:59 +00:00
if ( imageIndex > = ( int ) tables . size ( ) )
2022-06-08 10:54:34 +00:00
{
2022-06-09 09:30:04 +00:00
delete [ ] thumbData ;
2022-06-08 10:54:34 +00:00
delete [ ] imgData ;
return - 1 ;
}
2022-06-11 06:18:33 +00:00
int ret ;
char sql [ 1024 ] ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-22 12:38:39 +00:00
int id = tables [ imageIndex ] . id ;
sprintf ( sql , " update 'table_%s' set format = '%s', image = ?, thumb = ? where id = '%d' " ,
m_currBatchId . c_str ( ) , imgFormat . c_str ( ) , id ) ;
2022-06-08 10:54:34 +00:00
sqlite3_stmt * stmt = NULL ;
ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_bind_blob ( stmt , 1 , imgData , ( int ) imgSize , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-09 09:30:04 +00:00
ret = sqlite3_bind_blob ( stmt , 2 , thumbData , ( int ) thumbSize , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-08 10:54:34 +00:00
sqlite3_step ( stmt ) ;
ret = sqlite3_finalize ( stmt ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
delete [ ] thumbData ;
delete [ ] imgData ;
return - 1 ;
}
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
2022-06-08 10:54:34 +00:00
assert ( 0 = = ret ) ;
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-11 09:54:04 +00:00
ModifyBindFolderImage ( tables , imageIndex , imgFormat , imgData , imgSize ) ;
2022-06-11 06:18:33 +00:00
}
2022-06-09 09:30:04 +00:00
delete [ ] thumbData ;
2022-06-08 10:54:34 +00:00
delete [ ] imgData ;
errInfo . clear ( ) ;
return 0 ;
}
int ManagerV2 : : ModifyImageByLocal ( int imageIndex , const std : : string & imagePath , std : : string & errInfo )
{
errInfo = " 错误 " ;
if ( NULL = = m_sqlite | | imageIndex < 0 | | imagePath . empty ( ) )
return - 1 ;
HGUInt imgSize = 0 ;
2022-06-09 09:30:04 +00:00
std : : string imgFormat ;
HGByte * imgData = LoadImageFromPath ( imagePath . c_str ( ) , imgSize , imgFormat ) ;
if ( NULL = = imgData )
return - 1 ;
2022-06-08 10:54:34 +00:00
2022-06-09 09:30:04 +00:00
HGUInt thumbSize = 0 ;
HGByte * thumbData = LoadThumbFromPath ( imagePath . c_str ( ) , thumbSize ) ;
if ( NULL = = thumbData )
2022-06-08 10:54:34 +00:00
{
2022-06-09 09:30:04 +00:00
delete [ ] imgData ;
2022-06-08 10:54:34 +00:00
return - 1 ;
2022-06-09 09:30:04 +00:00
}
2022-06-08 10:54:34 +00:00
2022-06-11 06:18:33 +00:00
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-08 10:54:34 +00:00
2022-06-22 07:41:59 +00:00
if ( imageIndex > = ( int ) tables . size ( ) )
2022-06-08 10:54:34 +00:00
{
2022-06-09 09:30:04 +00:00
delete [ ] thumbData ;
2022-06-08 10:54:34 +00:00
delete [ ] imgData ;
return - 1 ;
}
2022-06-11 06:18:33 +00:00
int ret ;
char sql [ 1024 ] ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-22 12:38:39 +00:00
int id = tables [ imageIndex ] . id ;
sprintf ( sql , " update 'table_%s' set format = '%s', image = ?, thumb = ? where id = '%d' " ,
m_currBatchId . c_str ( ) , imgFormat . c_str ( ) , id ) ;
2022-06-08 10:54:34 +00:00
sqlite3_stmt * stmt = NULL ;
ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_bind_blob ( stmt , 1 , imgData , ( int ) imgSize , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-09 09:30:04 +00:00
ret = sqlite3_bind_blob ( stmt , 2 , thumbData , ( int ) thumbSize , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-08 10:54:34 +00:00
sqlite3_step ( stmt ) ;
ret = sqlite3_finalize ( stmt ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
delete [ ] thumbData ;
delete [ ] imgData ;
return - 1 ;
}
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
2022-06-08 10:54:34 +00:00
assert ( 0 = = ret ) ;
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-11 09:54:04 +00:00
ModifyBindFolderImage ( tables , imageIndex , imgFormat , imgData , imgSize ) ;
2022-06-11 06:18:33 +00:00
}
2022-06-09 09:30:04 +00:00
delete [ ] thumbData ;
2022-06-08 10:54:34 +00:00
delete [ ] imgData ;
errInfo . clear ( ) ;
return 0 ;
}
int ManagerV2 : : MoveImage ( const std : : vector < int > & imageIndexList , const std : : string & mode , int target , std : : string & errInfo )
{
errInfo = " 错误 " ;
if ( NULL = = m_sqlite | | imageIndexList . empty ( ) | | target < 0 )
return - 1 ;
if ( " pos " ! = mode & & " index " ! = mode )
return - 1 ;
2022-06-11 06:18:33 +00:00
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-22 12:38:39 +00:00
std : : vector < BatchTableInfo > tables2 = tables ;
2022-06-08 10:54:34 +00:00
if ( tables . empty ( ) )
return - 1 ;
2022-06-22 07:41:59 +00:00
if ( " pos " = = mode & & target > ( int ) tables . size ( ) )
2022-06-08 10:54:34 +00:00
return - 1 ;
2022-06-22 07:41:59 +00:00
if ( " index " = = mode & & target > = ( int ) tables . size ( ) )
2022-06-08 10:54:34 +00:00
return - 1 ;
bool indexValid = true ;
for ( int i = 0 ; i < ( int ) imageIndexList . size ( ) ; + + i )
{
2022-06-22 12:38:39 +00:00
if ( imageIndexList [ i ] < 0 | | imageIndexList [ i ] > = ( int ) tables . size ( ) )
2022-06-08 10:54:34 +00:00
{
indexValid = false ;
break ;
}
}
if ( ! indexValid )
return - 1 ;
2022-06-22 12:38:39 +00:00
std : : vector < int > idList ;
for ( int i = 0 ; i < ( int ) imageIndexList . size ( ) ; + + i )
{
int id = tables [ imageIndexList [ i ] ] . id ;
idList . push_back ( id ) ;
}
2022-06-08 10:54:34 +00:00
if ( " pos " = = mode )
{
int posEx = target ;
2022-06-22 12:38:39 +00:00
for ( int i = 0 ; i < ( int ) idList . size ( ) ; + + i )
2022-06-08 10:54:34 +00:00
{
int oldIndex = - 1 ;
for ( int j = 0 ; j < ( int ) tables . size ( ) ; + + j )
{
2022-06-22 12:38:39 +00:00
if ( idList [ i ] = = tables [ j ] . id )
2022-06-08 10:54:34 +00:00
{
oldIndex = j ;
break ;
}
}
assert ( - 1 ! = oldIndex ) ;
2022-06-11 06:18:33 +00:00
BatchTableInfo info = tables [ oldIndex ] ;
2022-06-08 10:54:34 +00:00
if ( oldIndex < posEx )
- - posEx ;
tables . erase ( tables . begin ( ) + oldIndex ) ;
if ( posEx ! = ( int ) tables . size ( ) )
2022-06-11 06:18:33 +00:00
tables . insert ( tables . begin ( ) + posEx , info ) ;
2022-06-08 10:54:34 +00:00
else
2022-06-11 06:18:33 +00:00
tables . push_back ( info ) ;
2022-06-08 10:54:34 +00:00
+ + posEx ;
}
}
else
{
2022-06-11 06:18:33 +00:00
std : : vector < BatchTableInfo > infos ;
2022-06-22 12:38:39 +00:00
for ( int i = 0 ; i < ( int ) idList . size ( ) ; + + i )
2022-06-08 10:54:34 +00:00
{
int oldIndex = - 1 ;
for ( int j = 0 ; j < ( int ) tables . size ( ) ; + + j )
{
2022-06-22 12:38:39 +00:00
if ( idList [ i ] = = tables [ j ] . id )
2022-06-08 10:54:34 +00:00
{
oldIndex = j ;
break ;
}
}
assert ( - 1 ! = oldIndex ) ;
2022-06-11 06:18:33 +00:00
BatchTableInfo info = tables [ oldIndex ] ;
2022-06-08 10:54:34 +00:00
tables . erase ( tables . begin ( ) + oldIndex ) ;
2022-06-11 06:18:33 +00:00
infos . push_back ( info ) ;
2022-06-08 10:54:34 +00:00
}
if ( target < ( int ) tables . size ( ) )
{
int indexEx = target ;
2022-06-11 06:18:33 +00:00
for ( int i = 0 ; i < ( int ) infos . size ( ) ; + + i )
2022-06-08 10:54:34 +00:00
{
2022-06-11 06:18:33 +00:00
tables . insert ( tables . begin ( ) + indexEx , infos [ i ] ) ;
2022-06-08 10:54:34 +00:00
+ + indexEx ;
}
}
else
{
2022-06-11 06:18:33 +00:00
for ( int i = 0 ; i < ( int ) infos . size ( ) ; + + i )
2022-06-08 10:54:34 +00:00
{
2022-06-11 06:18:33 +00:00
tables . push_back ( infos [ i ] ) ;
2022-06-08 10:54:34 +00:00
}
}
}
2022-06-11 06:18:33 +00:00
int ret ;
char sql [ 1024 ] ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
bool ok = true ;
2022-06-08 10:54:34 +00:00
for ( int i = 0 ; i < ( int ) tables . size ( ) ; + + i )
{
2022-06-22 12:38:39 +00:00
sprintf ( sql , " update 'table_%s_idx' set idx = '%d' where id = '%d' " ,
2022-06-11 06:18:33 +00:00
m_currBatchId . c_str ( ) , i , tables [ i ] . id ) ;
2022-06-08 10:54:34 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ok = false ;
break ;
}
}
if ( ! ok )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
2022-06-08 10:54:34 +00:00
assert ( 0 = = ret ) ;
2022-06-22 07:41:59 +00:00
return - 1 ;
2022-06-08 10:54:34 +00:00
}
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-22 12:38:39 +00:00
ClearBindFolderImageList ( tables2 ) ;
2022-06-11 06:18:33 +00:00
UpdateBindFolder ( ) ;
}
2022-06-08 10:54:34 +00:00
errInfo . clear ( ) ;
return 0 ;
}
2022-06-11 06:18:33 +00:00
int ManagerV2 : : ExchangeImage ( int imageIndex1 , int imageIndex2 , std : : string & errInfo )
2022-06-08 10:54:34 +00:00
{
errInfo = " 错误 " ;
2022-06-11 06:18:33 +00:00
if ( NULL = = m_sqlite | | imageIndex1 = = imageIndex2 )
2022-06-08 10:54:34 +00:00
return - 1 ;
2022-06-11 06:18:33 +00:00
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-08 10:54:34 +00:00
2022-07-05 02:36:01 +00:00
if ( imageIndex1 < 0 | | imageIndex1 > = ( int ) tables . size ( )
2022-06-22 12:38:39 +00:00
| | imageIndex2 < 0 | | imageIndex2 > = ( int ) tables . size ( ) )
2022-06-11 06:18:33 +00:00
return - 1 ;
int ret ;
char sql [ 1024 ] ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-22 12:38:39 +00:00
sprintf ( sql , " update 'table_%s_idx' set idx = '%d' where id = '%d' " ,
2022-06-11 06:18:33 +00:00
m_currBatchId . c_str ( ) , imageIndex2 , tables [ imageIndex1 ] . id ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
2022-06-11 06:18:33 +00:00
2022-06-22 12:38:39 +00:00
sprintf ( sql , " update 'table_%s_idx' set idx = '%d' where id = '%d' " ,
2022-06-11 06:18:33 +00:00
m_currBatchId . c_str ( ) , imageIndex1 , tables [ imageIndex2 ] . id ) ;
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return - 1 ;
}
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
2022-06-11 06:18:33 +00:00
assert ( 0 = = ret ) ;
2022-06-08 10:54:34 +00:00
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-11 09:54:04 +00:00
ExchangeBindFolderImage ( tables , imageIndex1 , imageIndex2 ) ;
2022-06-08 10:54:34 +00:00
}
2022-06-11 06:18:33 +00:00
errInfo . clear ( ) ;
return 0 ;
}
int ManagerV2 : : ImageBookSort ( std : : string & errInfo )
{
errInfo = " 错误 " ;
2022-06-08 10:54:34 +00:00
2022-06-11 06:18:33 +00:00
if ( NULL = = m_sqlite )
return - 1 ;
std : : vector < BatchTableInfo > tables ;
GetBatchTableInfo ( tables ) ;
2022-06-22 12:38:39 +00:00
std : : vector < BatchTableInfo > tables2 = tables ;
2022-06-11 06:18:33 +00:00
std : : list < BatchTableInfo > infos1 , infos2 ;
2022-06-08 10:54:34 +00:00
for ( int i = 0 ; i < ( int ) tables . size ( ) ; + + i )
{
2022-06-11 06:18:33 +00:00
BatchTableInfo info = tables [ i ] ;
2022-06-08 10:54:34 +00:00
if ( 0 = = i % 2 )
2022-06-11 06:18:33 +00:00
infos1 . push_back ( info ) ;
2022-06-08 10:54:34 +00:00
else
2022-06-11 06:18:33 +00:00
infos2 . push_front ( info ) ;
2022-06-08 10:54:34 +00:00
}
tables . clear ( ) ;
2022-06-11 06:18:33 +00:00
std : : list < BatchTableInfo > : : const_iterator iter ;
for ( iter = infos1 . begin ( ) ; iter ! = infos1 . end ( ) ; + + iter )
2022-06-08 10:54:34 +00:00
tables . push_back ( * iter ) ;
2022-06-11 06:18:33 +00:00
for ( iter = infos2 . begin ( ) ; iter ! = infos2 . end ( ) ; + + iter )
2022-06-08 10:54:34 +00:00
tables . push_back ( * iter ) ;
2022-06-11 06:18:33 +00:00
int ret ;
char sql [ 1024 ] ;
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
bool ok = true ;
2022-06-08 10:54:34 +00:00
for ( int i = 0 ; i < ( int ) tables . size ( ) ; + + i )
{
2022-06-22 12:38:39 +00:00
sprintf ( sql , " update 'table_%s_idx' set idx = '%d' where id = '%d' " ,
2022-06-11 06:18:33 +00:00
m_currBatchId . c_str ( ) , i , tables [ i ] . id ) ;
2022-06-08 10:54:34 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ok = false ;
break ;
}
}
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
2022-06-08 10:54:34 +00:00
assert ( 0 = = ret ) ;
2022-06-22 07:41:59 +00:00
return - 1 ;
2022-06-08 10:54:34 +00:00
}
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-11 06:18:33 +00:00
if ( ! m_bindFolder . empty ( ) )
{
2022-06-22 12:38:39 +00:00
ClearBindFolderImageList ( tables2 ) ;
2022-06-11 06:18:33 +00:00
UpdateBindFolder ( ) ;
}
2022-06-08 10:54:34 +00:00
errInfo . clear ( ) ;
return 0 ;
}
2022-06-11 09:54:04 +00:00
int ManagerV2 : : LoadBase64 ( const std : : string & fileName , std : : string & base64 )
{
base64 . clear ( ) ;
int ret = - 1 ;
FILE * file = fopen ( fileName . c_str ( ) , " rb " ) ;
if ( NULL ! = file )
{
fseek ( file , 0 , SEEK_END ) ;
long size = ftell ( file ) ;
fseek ( file , 0 , SEEK_SET ) ;
if ( size > 0 )
{
HGByte * data = new HGByte [ size ] ;
long readLen = ( long ) fread ( data , 1 , size , file ) ;
if ( readLen = = size )
{
HGSize base64Size = 0 ;
HGBase_Base64Encode ( data , size , NULL , & base64Size ) ;
uint8_t * base64Data = new uint8_t [ base64Size + 1 ] ;
HGBase_Base64Encode ( data , size , base64Data , & base64Size ) ;
base64Data [ base64Size ] = 0 ;
base64 = ( const char * ) base64Data ;
delete [ ] base64Data ;
ret = 0 ;
}
delete [ ] data ;
}
fclose ( file ) ;
}
return ret ;
}
int ManagerV2 : : SaveBase64 ( const std : : string & base64 , const std : : string & fileName )
{
if ( base64 . empty ( ) )
return - 1 ;
const char * base64Data = base64 . c_str ( ) ;
size_t base64Size = base64 . size ( ) ;
int ret = - 1 ;
FILE * file = fopen ( fileName . c_str ( ) , " wb " ) ;
if ( NULL ! = file )
{
HGSize size = 0 ;
HGBase_Base64Decode ( ( const HGByte * ) base64Data , ( HGSize ) base64Size , NULL , & size ) ;
uint8_t * data = new HGByte [ size ] ;
HGBase_Base64Decode ( ( const HGByte * ) base64Data , ( HGSize ) base64Size , data , & size ) ;
size_t writeLen = fwrite ( data , 1 , size , file ) ;
if ( writeLen = = ( size_t ) size )
ret = 0 ;
delete [ ] data ;
fclose ( file ) ;
}
2022-11-23 03:17:13 +00:00
else
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " ManagerV2::SaveBase64 Create File Fail %s " , fileName . c_str ( ) ) ;
}
2022-06-11 09:54:04 +00:00
if ( 0 ! = ret )
HGBase_DeleteFile ( fileName . c_str ( ) ) ;
2022-06-10 03:54:00 +00:00
return ret ;
2022-06-08 10:54:34 +00:00
}
std : : string ManagerV2 : : GetCfgStringValue ( const std : : string & app , const std : : string & key , const std : : string & def )
{
HGChar cfgPath [ 256 ] ;
HGBase_GetConfigPath ( cfgPath , 256 ) ;
strcat ( cfgPath , " config2.ini " ) ;
HGChar val [ 256 ] = { 0 } ;
HGBase_GetProfileString ( cfgPath , app . c_str ( ) , key . c_str ( ) , def . c_str ( ) , val , 256 ) ;
return val ;
}
int ManagerV2 : : GetCfgIntValue ( const std : : string & app , const std : : string & key , int def )
{
HGChar cfgPath [ 256 ] ;
HGBase_GetConfigPath ( cfgPath , 256 ) ;
strcat ( cfgPath , " config2.ini " ) ;
HGInt val = 0 ;
HGBase_GetProfileInt ( cfgPath , app . c_str ( ) , key . c_str ( ) , def , & val ) ;
return val ;
}
double ManagerV2 : : GetCfgDoubleValue ( const std : : string & app , const std : : string & key , double def )
{
HGChar cfgPath [ 256 ] ;
HGBase_GetConfigPath ( cfgPath , 256 ) ;
strcat ( cfgPath , " config2.ini " ) ;
char defStr [ 32 ] ;
sprintf ( defStr , " %f " , def ) ;
HGChar val [ 256 ] = { 0 } ;
HGBase_GetProfileString ( cfgPath , app . c_str ( ) , key . c_str ( ) , defStr , val , 256 ) ;
return atof ( val ) ;
}
bool ManagerV2 : : GetCfgBoolValue ( const std : : string & app , const std : : string & key , bool def )
{
HGChar cfgPath [ 256 ] ;
HGBase_GetConfigPath ( cfgPath , 256 ) ;
strcat ( cfgPath , " config2.ini " ) ;
HGInt val = 0 ;
HGBase_GetProfileInt ( cfgPath , app . c_str ( ) , key . c_str ( ) , ( HGInt ) def , & val ) ;
return ( bool ) val ;
}
bool ManagerV2 : : SetCfgStringValue ( const std : : string & app , const std : : string & key , const std : : string & val )
{
HGChar cfgPath [ 256 ] ;
HGBase_GetConfigPath ( cfgPath , 256 ) ;
HGBase_CreateDir ( cfgPath ) ;
strcat ( cfgPath , " config2.ini " ) ;
return ( HGBASE_ERR_OK = = HGBase_SetProfileString ( cfgPath , app . c_str ( ) , key . c_str ( ) , val . c_str ( ) ) ) ;
}
bool ManagerV2 : : SetCfgIntValue ( const std : : string & app , const std : : string & key , int val )
{
HGChar cfgPath [ 256 ] ;
HGBase_GetConfigPath ( cfgPath , 256 ) ;
HGBase_CreateDir ( cfgPath ) ;
strcat ( cfgPath , " config2.ini " ) ;
return ( HGBASE_ERR_OK = = HGBase_SetProfileInt ( cfgPath , app . c_str ( ) , key . c_str ( ) , val ) ) ;
}
bool ManagerV2 : : SetCfgDoubleValue ( const std : : string & app , const std : : string & key , double val )
{
HGChar cfgPath [ 256 ] ;
HGBase_GetConfigPath ( cfgPath , 256 ) ;
HGBase_CreateDir ( cfgPath ) ;
strcat ( cfgPath , " config2.ini " ) ;
char valStr [ 32 ] ;
sprintf ( valStr , " %f " , val ) ;
return ( HGBASE_ERR_OK = = HGBase_SetProfileString ( cfgPath , app . c_str ( ) , key . c_str ( ) , valStr ) ) ;
}
bool ManagerV2 : : SetCfgBoolValue ( const std : : string & app , const std : : string & key , bool val )
{
HGChar cfgPath [ 256 ] ;
HGBase_GetConfigPath ( cfgPath , 256 ) ;
HGBase_CreateDir ( cfgPath ) ;
strcat ( cfgPath , " config2.ini " ) ;
return ( HGBASE_ERR_OK = = HGBase_SetProfileInt ( cfgPath , app . c_str ( ) , key . c_str ( ) , ( HGInt ) val ) ) ;
}
2022-06-29 09:46:00 +00:00
static int xferinfo ( void * p , curl_off_t dltotal , curl_off_t dlnow , curl_off_t ultotal , curl_off_t ulnow )
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " ulnow=%lld, ultotal=%lld " , ulnow , ultotal ) ;
return 0 ;
}
2022-06-01 10:36:22 +00:00
int ManagerV2 : : HttpUpload ( const std : : string & host , int port , const std : : string & path ,
const std : : string & filePath , const std : : string & remoteFilePath )
{
2022-06-24 05:52:34 +00:00
int ret = - 1 ;
CURL * curl = curl_easy_init ( ) ;
2022-07-02 02:40:30 +00:00
if ( NULL ! = curl )
2022-06-24 05:52:34 +00:00
{
struct curl_httppost * formpost = NULL ;
struct curl_httppost * lastptr = NULL ;
curl_formadd ( & formpost , & lastptr , CURLFORM_COPYNAME , " filename " , CURLFORM_FILE , filePath . c_str ( ) , CURLFORM_END ) ;
curl_formadd ( & formpost , & lastptr , CURLFORM_COPYNAME , " remote_filename " , CURLFORM_COPYCONTENTS , remoteFilePath . c_str ( ) , CURLFORM_END ) ;
curl_formadd ( & formpost , & lastptr , CURLFORM_COPYNAME , " submit " , CURLFORM_COPYCONTENTS , " Submit " , CURLFORM_END ) ;
char url [ 512 ] ;
sprintf ( url , " http://%s:%d%s " , host . c_str ( ) , port , path . c_str ( ) ) ;
2022-06-24 08:03:08 +00:00
curl_easy_setopt ( curl , CURLOPT_CONNECTTIMEOUT , 2 ) ;
2022-06-24 05:52:34 +00:00
curl_easy_setopt ( curl , CURLOPT_URL , url ) ;
curl_easy_setopt ( curl , CURLOPT_HTTPPOST , formpost ) ;
2022-06-29 09:46:00 +00:00
curl_easy_setopt ( curl , CURLOPT_XFERINFOFUNCTION , xferinfo ) ;
curl_easy_setopt ( curl , CURLOPT_NOPROGRESS , 0 ) ;
2022-06-24 05:52:34 +00:00
/* Perform the request, res will get the return code */
CURLcode res = curl_easy_perform ( curl ) ;
/* Check for errors */
if ( res ! = CURLE_OK )
fprintf ( stderr , " curl_easy_perform() failed: %s " , curl_easy_strerror ( res ) ) ;
else
ret = 0 ;
/* then cleanup the formpost chain */
curl_formfree ( formpost ) ;
2022-07-02 02:40:30 +00:00
/* always cleanup */
curl_easy_cleanup ( curl ) ;
2022-06-24 05:52:34 +00:00
}
return ret ;
2022-06-01 10:36:22 +00:00
}
static size_t read_callback ( char * ptr , size_t size , size_t nmemb , void * stream )
{
unsigned long nread ;
/* in real-world cases, this would probably get this data differently
as this fread ( ) stuff is exactly what the library already would do
by default internally */
size_t retcode = fread ( ptr , size , nmemb , ( FILE * ) stream ) ;
if ( retcode > 0 )
{
nread = ( unsigned long ) retcode ;
//fprintf(stderr, "*** We read %lu bytes from file\n", nread);
}
return retcode ;
}
int ManagerV2 : : FtpUpload ( const std : : string & user , const std : : string & password , const std : : string & host , int port ,
const std : : string & filePath , const std : : string & remoteFilePath )
{
FILE * file = fopen ( filePath . c_str ( ) , " rb " ) ;
if ( NULL = = file )
{
return - 1 ;
}
int ret = - 1 ;
fseek ( file , 0 , SEEK_END ) ;
long fsize = ftell ( file ) ;
fseek ( file , 0 , SEEK_SET ) ;
/* get a curl handle */
CURL * curl = curl_easy_init ( ) ;
if ( NULL ! = curl )
{
/* we want to use our own read function */
curl_easy_setopt ( curl , CURLOPT_READFUNCTION , read_callback ) ;
curl_easy_setopt ( curl , CURLOPT_UPLOAD , 1L ) ;
char url [ 512 ] ;
if ( ! user . empty ( ) & & ! password . empty ( ) )
{
2022-06-24 05:52:34 +00:00
sprintf ( url , " ftp://%s:%s@%s:%d%s " , user . c_str ( ) , password . c_str ( ) ,
host . c_str ( ) , port , remoteFilePath . c_str ( ) ) ;
2022-06-01 10:36:22 +00:00
}
else
{
2022-06-24 05:52:34 +00:00
sprintf ( url , " ftp://%s:%d%s " , host . c_str ( ) , port , remoteFilePath . c_str ( ) ) ;
2022-06-01 10:36:22 +00:00
}
2022-06-24 08:03:08 +00:00
curl_easy_setopt ( curl , CURLOPT_CONNECTTIMEOUT , 2 ) ;
curl_easy_setopt ( curl , CURLOPT_URL , url ) ;
2022-06-01 10:36:22 +00:00
curl_easy_setopt ( curl , CURLOPT_FTP_CREATE_MISSING_DIRS , 1 ) ;
/* now specify which file to upload */
curl_easy_setopt ( curl , CURLOPT_READDATA , file ) ;
/* Set the size of the file to upload (optional). If you give a *_LARGE
option you MUST make sure that the type of the passed - in argument is a
curl_off_t . If you use CURLOPT_INFILESIZE ( without _LARGE ) you must
make sure that to pass in a type ' long ' argument . */
curl_easy_setopt ( curl , CURLOPT_INFILESIZE_LARGE , ( curl_off_t ) fsize ) ;
2022-06-29 09:46:00 +00:00
curl_easy_setopt ( curl , CURLOPT_XFERINFOFUNCTION , xferinfo ) ;
curl_easy_setopt ( curl , CURLOPT_NOPROGRESS , 0 ) ;
2022-06-01 10:36:22 +00:00
/* Now run off and do what you have been told! */
CURLcode res = curl_easy_perform ( curl ) ;
/* Check for errors */
if ( res ! = CURLE_OK )
fprintf ( stderr , " curl_easy_perform() failed: %s \n " , curl_easy_strerror ( res ) ) ;
else
ret = 0 ;
/* always cleanup */
curl_easy_cleanup ( curl ) ;
}
2022-07-02 02:40:30 +00:00
fclose ( file ) ; /* close the local file */
2022-05-23 10:29:23 +00:00
return ret ;
}
2022-06-22 07:41:59 +00:00
std : : string ManagerV2 : : GetFilePath ( bool temp , const std : : string & suffix )
2022-05-23 10:29:23 +00:00
{
2022-06-22 07:41:59 +00:00
HGChar savePath [ 256 ] = { 0 } ;
if ( temp )
HGBase_GetTmpPath ( savePath , 256 ) ;
else
strcpy ( savePath , m_globalCfg . fileSavePath . c_str ( ) ) ;
HGBase_CreateDir ( savePath ) ;
2022-06-09 10:11:44 +00:00
2022-05-23 10:29:23 +00:00
char filePath [ 256 ] = { 0 } ;
2022-06-10 03:54:00 +00:00
while ( 1 )
2022-05-23 10:29:23 +00:00
{
2022-06-10 03:54:00 +00:00
if ( " random " = = m_globalCfg . fileNameMode )
{
HGChar uuid [ 256 ] ;
HGBase_GetUuid ( uuid , 256 ) ;
2022-06-22 07:41:59 +00:00
sprintf ( filePath , " %s%s%s.%s " , savePath , m_globalCfg . fileNamePrefix . c_str ( ) , uuid , suffix . c_str ( ) ) ;
2022-06-10 03:54:00 +00:00
}
2024-01-12 01:16:53 +00:00
else if ( " sn_date_time " = = m_globalCfg . fileNameMode )
{
HGTimeInfo timeInfo ;
HGBase_GetLocalTime ( & timeInfo ) ;
sprintf ( filePath , " %s%s%s_%04d%02d%02d%02d%02d%02d%03d.%s " , savePath , m_globalCfg . fileNamePrefix . c_str ( ) , m_sn . c_str ( ) , timeInfo . year ,
timeInfo . month , timeInfo . day , timeInfo . hour , timeInfo . minute , timeInfo . second , timeInfo . milliseconds , suffix . c_str ( ) ) ;
}
2024-04-23 09:50:11 +00:00
else if ( " folder_time_img_order " = = m_globalCfg . fileNameMode )
{
if ( ! m_curBatchTime . empty ( ) )
{
strcat ( savePath , m_curBatchTime . c_str ( ) ) ;
strcat ( savePath , " / " ) ;
HGBase_StandardiseFileName ( savePath , savePath , 256 ) ;
}
HGBase_CreateDir ( savePath ) ;
HGTimeInfo timeInfo ;
HGBase_GetLocalTime ( & timeInfo ) ;
sprintf ( filePath , " %s%s%s.%s " , savePath , m_globalCfg . fileNamePrefix . c_str ( ) , std : : to_string ( m_curImgIndex ) . c_str ( ) , suffix . c_str ( ) ) ;
}
2022-06-10 03:54:00 +00:00
else
{
HGTimeInfo timeInfo ;
HGBase_GetLocalTime ( & timeInfo ) ;
2022-06-22 07:41:59 +00:00
sprintf ( filePath , " %s%s%04d%02d%02d%02d%02d%02d%03d.%s " , savePath , m_globalCfg . fileNamePrefix . c_str ( ) , timeInfo . year ,
2022-06-10 03:54:00 +00:00
timeInfo . month , timeInfo . day , timeInfo . hour , timeInfo . minute , timeInfo . second , timeInfo . milliseconds , suffix . c_str ( ) ) ;
}
# if defined(HG_CMP_MSC)
DWORD attr = GetFileAttributesA ( filePath ) ;
if ( INVALID_FILE_ATTRIBUTES = = attr )
break ;
# else
struct stat buf ;
2022-06-14 10:43:40 +00:00
int result = stat ( filePath , & buf ) ;
2022-06-10 03:54:00 +00:00
if ( 0 ! = result )
break ;
# endif
2022-05-23 10:29:23 +00:00
}
return filePath ;
}
2022-06-22 07:41:59 +00:00
int ManagerV2 : : SaveImage ( HGImage image , bool temp , std : : string & imagePath )
2022-05-23 10:29:23 +00:00
{
2022-06-01 10:36:22 +00:00
assert ( NULL ! = image ) ;
imagePath . clear ( ) ;
bool ocr = false ;
std : : string suffix = m_globalCfg . imageFormat ;
if ( " ocr-pdf " = = m_globalCfg . imageFormat )
{
suffix = " pdf " ;
ocr = true ;
}
else if ( " ocr-ofd " = = m_globalCfg . imageFormat )
{
suffix = " ofd " ;
ocr = true ;
}
2022-06-22 07:41:59 +00:00
std : : string imagePath2 = GetFilePath ( temp , suffix ) ;
2022-06-01 10:36:22 +00:00
int ret = - 1 ;
if ( ocr )
{
HGOCRMgr ocrMgr = NULL ;
2022-10-22 05:20:20 +00:00
HGImgProc_CreateOCRMgr ( 0 , & ocrMgr ) ;
2022-06-01 10:36:22 +00:00
if ( NULL ! = ocrMgr )
{
if ( HGBASE_ERR_OK = = HGImgProc_ImageOCRToFile ( ocrMgr , image , 0 , imagePath2 . c_str ( ) ) )
{
ret = 0 ;
}
HGImgProc_DestroyOCRMgr ( ocrMgr ) ;
}
}
else
{
HGImgFmtSaveInfo saveInfo ;
saveInfo . jpegQuality = m_globalCfg . imageJpegQuality ;
saveInfo . tiffJpegQuality = m_globalCfg . imageTiffJpegQuality ;
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_LZW ;
if ( " none " = = m_globalCfg . imageTiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_NONE ;
else if ( " jpeg " = = m_globalCfg . imageTiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_JPEG ;
else if ( " ccitt-g4 " = = m_globalCfg . imageTiffCompression )
saveInfo . tiffCompression = HGIMGFMT_TIFFCOMP_CCITTFAX4 ;
if ( HGBASE_ERR_OK = = HGImgFmt_SaveImage ( image , 0 , & saveInfo , imagePath2 . c_str ( ) ) )
{
ret = 0 ;
}
}
if ( 0 = = ret )
imagePath = imagePath2 ;
return ret ;
}
2022-06-21 10:37:41 +00:00
void ManagerV2 : : LoadSaveFilePathList ( std : : list < std : : string > & savePathList )
2022-06-01 10:36:22 +00:00
{
savePathList . clear ( ) ;
2022-06-16 07:56:29 +00:00
sqlite3_stmt * stmt = NULL ;
char sql [ 256 ] ;
sprintf ( sql , " select * from save_filenames " ) ;
int ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-01 10:36:22 +00:00
2022-06-16 07:56:29 +00:00
ret = sqlite3_step ( stmt ) ;
while ( SQLITE_ROW = = ret )
2022-06-01 10:36:22 +00:00
{
2022-06-16 07:56:29 +00:00
std : : string fileName = ( const char * ) sqlite3_column_text ( stmt , 0 ) ;
2022-06-01 10:36:22 +00:00
# if defined(HG_CMP_MSC)
2022-06-16 07:56:29 +00:00
DWORD attr = GetFileAttributesA ( fileName . c_str ( ) ) ;
if ( INVALID_FILE_ATTRIBUTES ! = attr & & 0 = = ( FILE_ATTRIBUTE_DIRECTORY & attr ) )
savePathList . push_back ( fileName ) ;
2022-06-01 10:36:22 +00:00
# else
2022-06-16 07:56:29 +00:00
struct stat buf ;
int result = stat ( fileName . c_str ( ) , & buf ) ;
if ( 0 = = result & & 0 = = ( S_IFDIR & buf . st_mode ) )
savePathList . push_back ( fileName ) ;
2022-06-01 10:36:22 +00:00
# endif
2022-06-16 07:56:29 +00:00
ret = sqlite3_step ( stmt ) ;
2022-06-01 10:36:22 +00:00
}
2022-06-16 07:56:29 +00:00
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
2022-06-01 10:36:22 +00:00
}
2022-06-21 10:37:41 +00:00
void ManagerV2 : : RestoreSaveFilePathList ( const std : : list < std : : string > & savePathList )
2022-06-01 10:36:22 +00:00
{
2022-06-22 07:41:59 +00:00
int ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
2022-06-16 07:56:29 +00:00
assert ( 0 = = ret ) ;
2022-06-01 10:36:22 +00:00
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " delete from save_filenames " , NULL , NULL , NULL ) ;
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return ;
}
2022-06-21 10:37:41 +00:00
std : : list < std : : string > : : const_iterator iter ;
for ( iter = savePathList . begin ( ) ; iter ! = savePathList . end ( ) ; + + iter )
2022-06-01 10:36:22 +00:00
{
2022-06-16 07:56:29 +00:00
char sql [ 1024 ] ;
2022-06-21 10:37:41 +00:00
sprintf ( sql , " insert into save_filenames values ('%s') " , StdStringToUtf8 ( * iter ) . c_str ( ) ) ;
2022-06-16 07:56:29 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return ;
}
2022-06-01 10:36:22 +00:00
}
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-05-30 11:01:23 +00:00
}
2022-06-15 11:07:55 +00:00
void ManagerV2 : : LoadDeviceParams ( const std : : string & devName , std : : vector < DeviceParam > & devParams )
2022-06-06 10:51:34 +00:00
{
assert ( ! devName . empty ( ) ) ;
2022-06-15 11:07:55 +00:00
devParams . clear ( ) ;
2022-06-16 07:56:29 +00:00
sqlite3_stmt * stmt = NULL ;
char sql [ 256 ] ;
2022-10-09 02:07:32 +00:00
sprintf ( sql , " select * from device_params_2 " ) ;
2022-06-16 07:56:29 +00:00
int ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_step ( stmt ) ;
while ( SQLITE_ROW = = ret )
{
std : : string name = ( const char * ) sqlite3_column_text ( stmt , 0 ) ;
2022-10-09 02:07:32 +00:00
std : : string title = ( const char * ) sqlite3_column_text ( stmt , 1 ) ;
std : : string valueType = ( const char * ) sqlite3_column_text ( stmt , 2 ) ;
std : : string value = ( const char * ) sqlite3_column_text ( stmt , 3 ) ;
2022-06-16 07:56:29 +00:00
DeviceParam devParam ;
2022-10-09 02:07:32 +00:00
devParam . name = name ;
devParam . title = title ;
2022-06-16 07:56:29 +00:00
if ( " string " = = valueType )
devParam . stringValue = value ;
else if ( " int " = = valueType )
devParam . intValue = atoi ( value . c_str ( ) ) ;
else if ( " double " = = valueType )
devParam . doubleValue = atof ( value . c_str ( ) ) ;
else if ( " bool " = = valueType )
devParam . boolValue = ( bool ) atoi ( value . c_str ( ) ) ;
devParams . push_back ( devParam ) ;
ret = sqlite3_step ( stmt ) ;
}
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
2022-06-06 10:51:34 +00:00
}
2022-06-16 06:20:52 +00:00
void ManagerV2 : : RestoreDeviceParams ( const std : : string & devName , const std : : vector < DeviceParamsGroup > & devParams )
2022-06-06 10:51:34 +00:00
{
assert ( ! devName . empty ( ) ) ;
2022-06-16 07:56:29 +00:00
2022-06-22 07:41:59 +00:00
int ret = sqlite3_exec ( m_sqlite , " begin " , NULL , NULL , NULL ) ;
2022-06-16 07:56:29 +00:00
assert ( 0 = = ret ) ;
2022-10-09 02:07:32 +00:00
ret = sqlite3_exec ( m_sqlite , " delete from device_params_2 " , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return ;
}
2022-06-16 07:56:29 +00:00
for ( int i = 0 ; i < ( int ) devParams . size ( ) ; + + i )
{
for ( int j = 0 ; j < ( int ) devParams [ i ] . devParams . size ( ) ; + + j )
{
const DeviceParam & devParam = devParams [ i ] . devParams [ j ] ;
2022-07-05 02:36:01 +00:00
2022-06-16 07:56:29 +00:00
char sql [ 1024 ] ;
if ( 1 = = devParam . valueType )
2022-10-09 02:07:32 +00:00
sprintf ( sql , " insert into device_params_2 values ('%s', '%s', '%s', '%s') " ,
devParam . name . c_str ( ) , devParam . title . c_str ( ) , " string " , devParam . stringValue . c_str ( ) ) ;
2022-06-16 07:56:29 +00:00
else if ( 2 = = devParam . valueType )
2022-10-09 02:07:32 +00:00
sprintf ( sql , " insert into device_params_2 values ('%s', '%s', '%s', '%d') " ,
devParam . name . c_str ( ) , devParam . title . c_str ( ) , " int " , devParam . intValue ) ;
2022-06-16 07:56:29 +00:00
else if ( 3 = = devParam . valueType )
2022-10-09 02:07:32 +00:00
sprintf ( sql , " insert into device_params_2 values ('%s', '%s', '%s', '%f') " ,
devParam . name . c_str ( ) , devParam . title . c_str ( ) , " double " , devParam . doubleValue ) ;
2022-06-16 07:56:29 +00:00
else if ( 4 = = devParam . valueType )
2022-10-09 02:07:32 +00:00
sprintf ( sql , " insert into device_params_2 values ('%s', '%s', '%s', '%d') " ,
devParam . name . c_str ( ) , devParam . title . c_str ( ) , " bool " , ( int ) devParam . boolValue ) ;
2022-06-16 07:56:29 +00:00
ret = sqlite3_exec ( m_sqlite , sql , NULL , NULL , NULL ) ;
2022-06-22 07:41:59 +00:00
if ( 0 ! = ret )
{
ret = sqlite3_exec ( m_sqlite , " rollback " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
return ;
}
2022-06-16 07:56:29 +00:00
}
}
2022-06-22 07:41:59 +00:00
ret = sqlite3_exec ( m_sqlite , " commit " , NULL , NULL , NULL ) ;
assert ( 0 = = ret ) ;
2022-06-06 10:51:34 +00:00
}
2022-06-15 11:07:55 +00:00
int ManagerV2 : : SetParamsToDevice ( SANE_Handle hdev , const std : : vector < DeviceParam > & devParams )
2022-06-06 10:51:34 +00:00
{
assert ( NULL ! = hdev ) ;
2022-06-15 11:07:55 +00:00
if ( devParams . empty ( ) )
return - 1 ;
2022-06-06 10:51:34 +00:00
2022-06-15 11:07:55 +00:00
int ret = 0 ;
for ( int i = 0 ; i < ( int ) devParams . size ( ) ; + + i )
2022-06-06 10:51:34 +00:00
{
2022-06-15 11:07:55 +00:00
bool find = false ;
2022-06-06 10:51:34 +00:00
2022-06-15 11:07:55 +00:00
SANE_Int num_dev_options = 0 ;
sane_control_option ( hdev , 0 , SANE_ACTION_GET_VALUE , & num_dev_options , NULL ) ;
for ( int j = 1 ; j < num_dev_options ; + + j )
2022-06-06 10:51:34 +00:00
{
2022-06-15 11:07:55 +00:00
const SANE_Option_Descriptor * desp = sane_get_option_descriptor ( hdev , j ) ;
if ( NULL = = desp )
continue ;
2022-10-09 02:07:32 +00:00
const char * name = desp - > name ;
while ( ' ' = = * name )
+ + name ;
2022-06-16 06:20:52 +00:00
const char * title = desp - > title ;
while ( ' ' = = * title )
+ + title ;
2022-10-09 02:07:32 +00:00
if ( 0 = = strcmp ( devParams [ i ] . name . c_str ( ) , name ) | | 0 = = strcmp ( devParams [ i ] . title . c_str ( ) , title ) )
2022-06-06 10:51:34 +00:00
{
2022-06-15 11:07:55 +00:00
if ( SANE_TYPE_STRING = = desp - > type )
{
if ( SANE_STATUS_GOOD ! = sane_control_option ( hdev , j , SANE_ACTION_SET_VALUE , ( void * ) devParams [ i ] . stringValue . c_str ( ) , NULL ) )
ret = - 1 ;
}
else if ( SANE_TYPE_INT = = desp - > type )
{
SANE_Int value = devParams [ i ] . intValue ;
if ( SANE_STATUS_GOOD ! = sane_control_option ( hdev , j , SANE_ACTION_SET_VALUE , & value , NULL ) )
ret = - 1 ;
}
else if ( SANE_TYPE_FIXED = = desp - > type )
{
SANE_Fixed value = SANE_FIX ( devParams [ i ] . doubleValue ) ;
if ( SANE_STATUS_GOOD ! = sane_control_option ( hdev , j , SANE_ACTION_SET_VALUE , & value , NULL ) )
ret = - 1 ;
}
else if ( SANE_TYPE_BOOL = = desp - > type )
{
SANE_Bool value = ( SANE_Bool ) devParams [ i ] . boolValue ;
if ( SANE_STATUS_GOOD ! = sane_control_option ( hdev , j , SANE_ACTION_SET_VALUE , & value , NULL ) )
ret = - 1 ;
}
find = true ;
break ;
2022-06-06 10:51:34 +00:00
}
}
2022-06-15 11:07:55 +00:00
if ( ! find )
ret = - 1 ;
2022-06-06 10:51:34 +00:00
}
return ret ;
}
2022-06-16 06:20:52 +00:00
int ManagerV2 : : GetParamsFromDevice ( SANE_Handle hdev , std : : vector < DeviceParamsGroup > & devParams )
2022-06-06 10:51:34 +00:00
{
assert ( NULL ! = hdev ) ;
2022-06-15 11:07:55 +00:00
devParams . clear ( ) ;
2022-06-06 10:51:34 +00:00
SANE_Int num_dev_options = 0 ;
sane_control_option ( hdev , 0 , SANE_ACTION_GET_VALUE , & num_dev_options , NULL ) ;
for ( int i = 1 ; i < num_dev_options ; + + i )
{
const SANE_Option_Descriptor * desp = sane_get_option_descriptor ( hdev , i ) ;
if ( NULL = = desp )
continue ;
2022-10-09 02:07:32 +00:00
const char * name = desp - > name ;
while ( ' ' = = * name )
+ + name ;
2024-04-29 10:02:18 +00:00
if ( 0 = = strcmp ( SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA , name ) )
continue ;
2022-06-16 06:20:52 +00:00
const char * title = desp - > title ;
while ( ' ' = = * title )
+ + title ;
2022-06-15 11:07:55 +00:00
2022-06-16 07:56:29 +00:00
//HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "device config, title=%s", Utf8ToStdString(title).c_str());
2022-06-15 11:07:55 +00:00
2022-06-16 06:20:52 +00:00
if ( SANE_TYPE_GROUP = = desp - > type )
{
DeviceParamsGroup group ;
2022-10-08 03:36:49 +00:00
group . groupTitle = title ;
2022-06-16 06:20:52 +00:00
devParams . push_back ( group ) ;
}
else if ( SANE_TYPE_STRING = = desp - > type )
2022-06-06 10:51:34 +00:00
{
char value [ 256 ] = { 0 } ;
sane_control_option ( hdev , i , SANE_ACTION_GET_VALUE , value , NULL ) ;
2022-06-16 06:20:52 +00:00
DeviceParam devParam ;
2022-10-09 02:07:32 +00:00
devParam . name = name ;
2022-06-16 06:20:52 +00:00
devParam . title = title ;
2022-06-15 11:07:55 +00:00
devParam . valueType = 1 ;
devParam . stringValue = value ;
2022-06-06 10:51:34 +00:00
2024-03-08 06:27:35 +00:00
if ( SANE_CONSTRAINT_STRING_LIST = = desp - > constraint_type )
{
2024-04-29 10:02:18 +00:00
devParam . rangeType = 1 ;
2024-03-08 06:27:35 +00:00
const SANE_String_Const * p = desp - > constraint . string_list ;
while ( NULL ! = * p )
{
devParam . stringValueList . push_back ( * p ) ;
+ + p ;
}
}
2024-04-29 10:02:18 +00:00
assert ( ! devParams . empty ( ) ) ;
devParams [ devParams . size ( ) - 1 ] . devParams . push_back ( devParam ) ;
2022-06-06 10:51:34 +00:00
}
else if ( SANE_TYPE_INT = = desp - > type )
{
SANE_Int value = 0 ;
sane_control_option ( hdev , i , SANE_ACTION_GET_VALUE , & value , NULL ) ;
2022-06-16 06:20:52 +00:00
DeviceParam devParam ;
2022-10-09 02:07:32 +00:00
devParam . name = name ;
2022-06-16 06:20:52 +00:00
devParam . title = title ;
2022-06-15 11:07:55 +00:00
devParam . valueType = 2 ;
devParam . intValue = ( int ) value ;
2022-06-06 10:51:34 +00:00
2022-06-15 11:07:55 +00:00
if ( SANE_CONSTRAINT_WORD_LIST = = desp - > constraint_type )
2022-06-06 10:51:34 +00:00
{
2022-06-15 11:07:55 +00:00
devParam . rangeType = 2 ;
const SANE_Word * p = desp - > constraint . word_list ;
for ( SANE_Int i = 0 ; i < p [ 0 ] ; + + i )
2022-06-06 10:51:34 +00:00
{
2022-06-15 11:07:55 +00:00
devParam . intValueList . push_back ( p [ i + 1 ] ) ;
2022-06-06 10:51:34 +00:00
}
}
2022-06-15 11:07:55 +00:00
else if ( SANE_CONSTRAINT_RANGE = = desp - > constraint_type )
2022-06-06 10:51:34 +00:00
{
2022-06-15 11:07:55 +00:00
devParam . rangeType = 4 ;
devParam . intValueMin = desp - > constraint . range - > min ;
devParam . intValueMax = desp - > constraint . range - > max ;
2022-06-06 10:51:34 +00:00
}
2022-06-16 06:20:52 +00:00
assert ( ! devParams . empty ( ) ) ;
devParams [ devParams . size ( ) - 1 ] . devParams . push_back ( devParam ) ;
2022-06-06 10:51:34 +00:00
}
else if ( SANE_TYPE_FIXED = = desp - > type )
{
SANE_Word value = 0 ;
sane_control_option ( hdev , i , SANE_ACTION_GET_VALUE , & value , NULL ) ;
2022-06-16 06:20:52 +00:00
DeviceParam devParam ;
2022-10-09 02:07:32 +00:00
devParam . name = name ;
2022-06-16 06:20:52 +00:00
devParam . title = title ;
2022-06-15 11:07:55 +00:00
devParam . valueType = 3 ;
devParam . doubleValue = SANE_UNFIX ( value ) ;
2022-06-06 10:51:34 +00:00
2022-06-15 11:07:55 +00:00
if ( SANE_CONSTRAINT_WORD_LIST = = desp - > constraint_type )
2022-06-06 10:51:34 +00:00
{
2022-06-15 11:07:55 +00:00
devParam . rangeType = 3 ;
const SANE_Word * p = desp - > constraint . word_list ;
for ( SANE_Int i = 0 ; i < p [ 0 ] ; + + i )
2022-06-06 10:51:34 +00:00
{
2022-06-15 11:07:55 +00:00
devParam . doubleValueList . push_back ( SANE_UNFIX ( p [ i + 1 ] ) ) ;
2022-06-06 10:51:34 +00:00
}
}
2022-06-15 11:07:55 +00:00
else if ( SANE_CONSTRAINT_RANGE = = desp - > constraint_type )
2022-06-06 10:51:34 +00:00
{
2022-06-15 11:07:55 +00:00
devParam . rangeType = 5 ;
devParam . doubleValueMin = SANE_UNFIX ( desp - > constraint . range - > min ) ;
devParam . doubleValueMax = SANE_UNFIX ( desp - > constraint . range - > max ) ;
2022-06-06 10:51:34 +00:00
}
2022-06-16 06:20:52 +00:00
assert ( ! devParams . empty ( ) ) ;
devParams [ devParams . size ( ) - 1 ] . devParams . push_back ( devParam ) ;
2022-06-06 10:51:34 +00:00
}
else if ( SANE_TYPE_BOOL = = desp - > type )
{
SANE_Bool value = 0 ;
sane_control_option ( hdev , i , SANE_ACTION_GET_VALUE , & value , NULL ) ;
2022-06-16 06:20:52 +00:00
DeviceParam devParam ;
2022-10-09 02:07:32 +00:00
devParam . name = name ;
2022-06-16 06:20:52 +00:00
devParam . title = title ;
2022-06-15 11:07:55 +00:00
devParam . valueType = 4 ;
devParam . boolValue = ( bool ) value ;
2022-06-16 06:20:52 +00:00
assert ( ! devParams . empty ( ) ) ;
devParams [ devParams . size ( ) - 1 ] . devParams . push_back ( devParam ) ;
2022-06-06 10:51:34 +00:00
}
2022-06-16 06:20:52 +00:00
}
return 0 ;
}
int ManagerV2 : : ResetParamsToDevice ( SANE_Handle hdev )
{
assert ( NULL ! = hdev ) ;
int ret = - 1 ;
2022-06-06 10:51:34 +00:00
2022-06-16 06:20:52 +00:00
SANE_Int num_dev_options = 0 ;
sane_control_option ( hdev , 0 , SANE_ACTION_GET_VALUE , & num_dev_options , NULL ) ;
for ( int i = 1 ; i < num_dev_options ; + + i )
{
const SANE_Option_Descriptor * desp = sane_get_option_descriptor ( hdev , i ) ;
if ( NULL = = desp )
continue ;
2022-10-08 03:36:49 +00:00
const char * name = desp - > name ;
while ( ' ' = = * name )
+ + name ;
2022-06-16 06:20:52 +00:00
2022-10-08 03:36:49 +00:00
if ( 0 = = strcmp ( SANE_STD_OPT_NAME_RESTORE , name ) & & SANE_TYPE_BUTTON = = desp - > type )
2022-06-15 11:07:55 +00:00
{
2022-06-16 06:20:52 +00:00
if ( SANE_STATUS_GOOD = = sane_control_option ( hdev , i , SANE_ACTION_SET_VALUE , NULL , NULL ) )
ret = 0 ;
break ;
2022-06-15 11:07:55 +00:00
}
2022-06-09 09:30:04 +00:00
}
2022-06-16 06:20:52 +00:00
return ret ;
2022-06-09 09:30:04 +00:00
}
HGByte * ManagerV2 : : LoadImageFromPath ( const std : : string & imagePath , HGUInt & size , std : : string & format )
{
size = 0 ;
format . clear ( ) ;
HGUInt imgType = 0 ;
HGImgFmt_GetImgFmtType ( imagePath . c_str ( ) , & imgType ) ;
if ( 0 = = imgType )
return NULL ;
std : : string imgFormat ;
if ( HGIMGFMT_TYPE_JPEG = = imgType )
imgFormat = " jpg " ;
else if ( HGIMGFMT_TYPE_BMP = = imgType )
imgFormat = " bmp " ;
else if ( HGIMGFMT_TYPE_PNG = = imgType )
imgFormat = " png " ;
else if ( HGIMGFMT_TYPE_TIFF = = imgType )
imgFormat = " tif " ;
else if ( HGIMGFMT_TYPE_PDF = = imgType )
imgFormat = " pdf " ;
else if ( HGIMGFMT_TYPE_OFD = = imgType )
imgFormat = " ofd " ;
if ( imgFormat . empty ( ) )
return NULL ;
HGByte * imgData = NULL ;
HGUInt imgSize = 0 ;
FILE * file = fopen ( imagePath . c_str ( ) , " rb " ) ;
if ( NULL ! = file )
{
fseek ( file , 0 , SEEK_END ) ;
imgSize = ftell ( file ) ;
fseek ( file , 0 , SEEK_SET ) ;
if ( imgSize > 0 )
{
imgData = new HGByte [ imgSize ] ;
HGUInt readLen = ( HGUInt ) fread ( imgData , 1 , imgSize , file ) ;
if ( readLen ! = imgSize )
{
delete [ ] imgData ;
imgData = NULL ;
imgSize = 0 ;
}
}
fclose ( file ) ;
}
if ( NULL = = imgData )
return NULL ;
size = imgSize ;
format = imgFormat ;
return imgData ;
2022-06-06 10:51:34 +00:00
}
2022-06-09 09:30:04 +00:00
HGByte * ManagerV2 : : LoadImageFromBase64 ( const std : : string & imageBase64 , HGUInt & size , std : : string & format )
{
size = 0 ;
format . clear ( ) ;
size_t pos = imageBase64 . find ( ' , ' ) ;
if ( std : : string : : npos = = pos )
return NULL ;
std : : string imgFormat ;
std : : string prefix = imageBase64 . substr ( 0 , pos + 1 ) ;
if ( " data:image/jpeg;base64, " = = prefix )
imgFormat = " jpg " ;
else if ( " data:image/bmp;base64, " = = prefix )
imgFormat = " bmp " ;
else if ( " data:image/png;base64, " = = prefix )
imgFormat = " png " ;
else if ( " data:image/tiff;base64, " = = prefix )
imgFormat = " tif " ;
else if ( " data:image/pdf;base64, " = = prefix )
imgFormat = " pdf " ;
else if ( " data:image/ofd;base64, " = = prefix )
imgFormat = " ofd " ;
if ( imgFormat . empty ( ) )
return NULL ;
HGByte * imgData = NULL ;
HGSize imgSize = 0 ;
const HGChar * base64Data = imageBase64 . c_str ( ) + pos + 1 ;
HGSize base64Size = ( HGSize ) strlen ( base64Data ) ;
HGBase_Base64Decode ( ( const HGByte * ) base64Data , ( HGSize ) base64Size , NULL , & imgSize ) ;
if ( 0 ! = imgSize )
{
imgData = new HGByte [ imgSize ] ;
HGBase_Base64Decode ( ( const HGByte * ) base64Data , ( HGSize ) base64Size , imgData , & imgSize ) ;
}
if ( NULL = = imgData )
return NULL ;
2022-06-13 11:56:43 +00:00
size = ( HGUInt ) imgSize ;
2022-06-09 09:30:04 +00:00
format = imgFormat ;
return imgData ;
}
HGByte * ManagerV2 : : LoadThumbFromPath ( const std : : string & imagePath , HGUInt & size )
{
size = 0 ;
HGUInt imgType = 0 ;
HGImgFmt_GetImgFmtType ( imagePath . c_str ( ) , & imgType ) ;
if ( 0 = = imgType )
return NULL ;
HGImage img = NULL ;
HGImgFmt_LoadImage ( imagePath . c_str ( ) , imgType , NULL , 0 , HGBASE_IMGORIGIN_TOP , & img ) ;
if ( NULL = = img )
return NULL ;
HGImageInfo imgInfo ;
HGBase_GetImageInfo ( img , & imgInfo ) ;
HGUInt width = imgInfo . width ;
HGUInt height = imgInfo . height ;
if ( width > = height )
{
if ( width > 240 )
{
width = 240 ;
height = HGMAX ( ( HGUInt ) ( 240.0 * imgInfo . height / imgInfo . width + 0.5 ) , 1 ) ;
}
}
else
{
if ( height > 240 )
{
height = 240 ;
width = HGMAX ( ( HGUInt ) ( 240.0 * imgInfo . width / imgInfo . height + 0.5 ) , 1 ) ;
}
}
HGImage img2 = NULL ;
HGBase_CreateImage ( width , height , imgInfo . type , HGBASE_IMGORIGIN_TOP , & img2 ) ;
if ( NULL = = img2 )
{
HGBase_DestroyImage ( img ) ;
return NULL ;
}
HGImgProc_ResizeImage ( img , img2 , HGIMGPROC_INTERPOTYPE_NN ) ;
HGBase_DestroyImage ( img ) ;
HGChar tmpName [ 256 ] ;
HGBase_GetTmpFileName ( NULL , tmpName , 256 ) ;
HGResult ret = HGImgFmt_SaveImage ( img2 , imgType , NULL , tmpName ) ;
HGBase_DestroyImage ( img2 ) ;
if ( HGBASE_ERR_OK ! = ret )
{
return NULL ;
}
HGByte * imgData = NULL ;
HGUInt imgSize = 0 ;
FILE * file = fopen ( tmpName , " rb " ) ;
if ( NULL ! = file )
{
fseek ( file , 0 , SEEK_END ) ;
imgSize = ftell ( file ) ;
fseek ( file , 0 , SEEK_SET ) ;
if ( imgSize > 0 )
{
imgData = new HGByte [ imgSize ] ;
HGUInt readLen = ( HGUInt ) fread ( imgData , 1 , imgSize , file ) ;
if ( readLen ! = imgSize )
{
delete [ ] imgData ;
imgData = NULL ;
imgSize = 0 ;
}
}
fclose ( file ) ;
}
HGBase_DeleteFile ( tmpName ) ;
if ( NULL = = imgData )
return NULL ;
size = imgSize ;
return imgData ;
}
HGByte * ManagerV2 : : LoadThumbFromBase64 ( const std : : string & imageBase64 , HGUInt & size )
{
size = 0 ;
size_t pos = imageBase64 . find ( ' , ' ) ;
if ( std : : string : : npos = = pos )
return NULL ;
HGChar tmpName [ 256 ] ;
HGBase_GetTmpFileName ( NULL , tmpName , 256 ) ;
if ( 0 ! = SaveBase64 ( imageBase64 . c_str ( ) + pos + 1 , tmpName ) )
return NULL ;
HGByte * data = LoadThumbFromPath ( tmpName , size ) ;
HGBase_DeleteFile ( tmpName ) ;
return data ;
}
bool ManagerV2 : : SaveToBase64 ( const HGByte * data , HGUInt size , std : : string & base64 )
2022-06-08 10:54:34 +00:00
{
assert ( NULL ! = data & & 0 ! = size ) ;
base64 . clear ( ) ;
HGSize base64Size = 0 ;
HGBase_Base64Encode ( data , size , NULL , & base64Size ) ;
uint8_t * p = new uint8_t [ base64Size + 1 ] ;
HGBase_Base64Encode ( data , size , p , & base64Size ) ;
p [ base64Size ] = 0 ;
base64 = ( const char * ) p ;
delete [ ] p ;
2022-06-09 09:30:04 +00:00
return true ;
}
bool ManagerV2 : : SaveToFile ( const HGByte * data , HGUInt size , const std : : string & filePath )
{
assert ( NULL ! = data & & 0 ! = size ) ;
bool ret = false ;
FILE * file = fopen ( filePath . c_str ( ) , " wb " ) ;
if ( NULL ! = file )
{
size_t writeLen = fwrite ( data , 1 , size , file ) ;
if ( writeLen = = ( size_t ) size )
ret = true ;
fclose ( file ) ;
}
2022-11-23 03:17:13 +00:00
else
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_ERROR , " ManagerV2::SaveToFile Create File Fail %s " , filePath . c_str ( ) ) ;
}
2022-06-09 09:30:04 +00:00
if ( ! ret )
HGBase_DeleteFile ( filePath . c_str ( ) ) ;
return ret ;
2022-06-08 10:54:34 +00:00
}
2022-06-22 12:38:39 +00:00
int ManagerV2 : : GetId ( int idx )
{
int id = - 1 ;
char sql [ 1024 ] ;
sprintf ( sql , " select id from 'table_%s_idx' where idx = '%d' " , m_currBatchId . c_str ( ) , idx ) ;
sqlite3_stmt * stmt = NULL ;
int ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_step ( stmt ) ;
if ( SQLITE_ROW = = ret )
id = sqlite3_column_int ( stmt , 0 ) ;
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
return id ;
}
2022-06-11 06:18:33 +00:00
void ManagerV2 : : GetBatchTableInfo ( std : : vector < BatchTableInfo > & tables )
{
tables . clear ( ) ;
2022-06-16 09:52:10 +00:00
sqlite3_stmt * stmt = NULL ;
2022-06-11 06:18:33 +00:00
char sql [ 256 ] ;
2022-07-05 02:36:01 +00:00
sprintf ( sql , " select table_%s.id, table_%s.format from table_%s join table_%s_idx on table_%s.id == table_%s_idx.id order by table_%s_idx.idx asc " ,
m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) ,
2022-06-22 12:38:39 +00:00
m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) ) ;
2022-06-16 09:52:10 +00:00
int ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
2022-06-11 06:18:33 +00:00
assert ( 0 = = ret ) ;
2022-06-16 09:52:10 +00:00
ret = sqlite3_step ( stmt ) ;
while ( SQLITE_ROW = = ret )
2022-06-11 06:18:33 +00:00
{
BatchTableInfo info ;
2022-06-16 09:52:10 +00:00
info . id = sqlite3_column_int ( stmt , 0 ) ;
2022-06-22 12:38:39 +00:00
info . format = ( const char * ) sqlite3_column_text ( stmt , 1 ) ;
2022-06-11 06:18:33 +00:00
tables . push_back ( info ) ;
2022-06-16 09:52:10 +00:00
ret = sqlite3_step ( stmt ) ;
2022-06-11 06:18:33 +00:00
}
2022-06-16 09:52:10 +00:00
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
2022-06-11 06:18:33 +00:00
}
2022-06-13 04:02:51 +00:00
void ManagerV2 : : ClearBindFolder ( )
{
assert ( ! m_bindFolder . empty ( ) ) ;
2022-06-14 10:43:40 +00:00
# if defined(HG_CMP_MSC)
2022-06-13 04:02:51 +00:00
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 ) ;
2022-06-14 10:43:40 +00:00
# else
2022-06-15 01:50:21 +00:00
DIR * dir = opendir ( m_bindFolder . c_str ( ) ) ;
if ( NULL ! = dir )
{
struct dirent * dire = NULL ;
while ( dire = readdir ( dir ) )
{
char fileName [ 256 ] ;
sprintf ( fileName , " %s%s " , m_bindFolder . c_str ( ) , dire - > d_name ) ;
2022-06-16 01:37:26 +00:00
struct stat filebuf ;
lstat ( fileName , & filebuf ) ;
if ( ! S_ISDIR ( filebuf . st_mode ) )
2022-06-15 01:50:21 +00:00
{
HGBase_DeleteFile ( fileName ) ;
}
}
closedir ( dir ) ;
}
2022-06-14 10:43:40 +00:00
# endif
2022-06-13 04:02:51 +00:00
}
2022-06-11 06:18:33 +00:00
void ManagerV2 : : UpdateBindFolder ( )
{
assert ( ! m_bindFolder . empty ( ) ) ;
if ( NULL = = m_sqlite )
return ;
sqlite3_stmt * stmt = NULL ;
2022-06-22 12:38:39 +00:00
char sql [ 1024 ] ;
sprintf ( sql , " select table_%s_idx.idx, table_%s.format, table_%s.image from table_%s join table_%s_idx on table_%s.id == table_%s_idx.id " ,
m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) ,
m_currBatchId . c_str ( ) , m_currBatchId . c_str ( ) ) ;
2022-06-11 06:18:33 +00:00
int ret = sqlite3_prepare ( m_sqlite , sql , - 1 , & stmt , NULL ) ;
assert ( 0 = = ret ) ;
ret = sqlite3_step ( stmt ) ;
while ( SQLITE_ROW = = ret )
{
2022-06-22 07:41:59 +00:00
int idx = sqlite3_column_int ( stmt , 0 ) ;
std : : string imgFmt = ( const char * ) sqlite3_column_text ( stmt , 1 ) ;
const void * imgData = sqlite3_column_blob ( stmt , 2 ) ;
int imgSize = sqlite3_column_bytes ( stmt , 2 ) ;
2022-06-11 06:18:33 +00:00
2022-06-13 04:02:51 +00:00
char fmt [ 24 ] ;
sprintf ( fmt , " %%s%%0%dd.%%s " , m_bindNameWidth ) ;
2022-06-11 06:18:33 +00:00
char imagePath [ 256 ] ;
2022-06-13 04:02:51 +00:00
sprintf ( imagePath , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + idx , imgFmt . c_str ( ) ) ;
2022-06-11 06:18:33 +00:00
HGBase_CreateDir ( m_bindFolder . c_str ( ) ) ;
SaveToFile ( ( const HGByte * ) imgData , imgSize , imagePath ) ;
ret = sqlite3_step ( stmt ) ;
}
ret = sqlite3_finalize ( stmt ) ;
assert ( 0 = = ret ) ;
}
2022-06-11 09:54:04 +00:00
void ManagerV2 : : InsertBindFolderImage ( const std : : vector < BatchTableInfo > & tables , int insertPos , const std : : string imgFmt ,
const HGByte * imgData , HGUInt imgSize )
{
assert ( ! m_bindFolder . empty ( ) ) ;
2022-06-13 04:02:51 +00:00
char fmt [ 24 ] ;
sprintf ( fmt , " %%s%%0%dd.%%s " , m_bindNameWidth ) ;
2022-06-11 09:54:04 +00:00
for ( int i = ( int ) tables . size ( ) - 1 ; i > = 0 ; - - i )
{
2022-06-22 12:38:39 +00:00
if ( i > = insertPos )
2022-06-11 09:54:04 +00:00
{
char fileName [ 256 ] ;
2022-06-22 12:38:39 +00:00
sprintf ( fileName , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + i , tables [ i ] . format . c_str ( ) ) ;
2022-06-11 09:54:04 +00:00
char destName [ 256 ] ;
2022-06-22 12:38:39 +00:00
sprintf ( destName , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + i + 1 , tables [ i ] . format . c_str ( ) ) ;
2022-06-14 10:43:40 +00:00
# if defined(HG_CMP_MSC)
2022-06-11 09:54:04 +00:00
MoveFileA ( fileName , destName ) ;
2022-06-14 10:43:40 +00:00
# else
rename ( fileName , destName ) ;
# endif
2022-06-11 09:54:04 +00:00
}
}
char fileName [ 256 ] ;
2022-06-13 04:02:51 +00:00
sprintf ( fileName , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + insertPos , imgFmt . c_str ( ) ) ;
2022-06-11 09:54:04 +00:00
SaveToFile ( imgData , imgSize , fileName ) ;
}
2022-06-14 10:43:40 +00:00
void ManagerV2 : : ModifyBindFolderImage ( const std : : vector < BatchTableInfo > & tables , int imageIndex , const std : : string imgFmt ,
2022-06-11 09:54:04 +00:00
const HGByte * imgData , HGUInt imgSize )
{
assert ( ! m_bindFolder . empty ( ) ) ;
2022-06-13 04:02:51 +00:00
char fmt [ 24 ] ;
sprintf ( fmt , " %%s%%0%dd.%%s " , m_bindNameWidth ) ;
2022-06-22 12:38:39 +00:00
std : : string oldFormat = tables [ imageIndex ] . format ;
2022-06-11 09:54:04 +00:00
char oldFileName [ 256 ] ;
2022-06-13 04:02:51 +00:00
sprintf ( oldFileName , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + imageIndex , oldFormat . c_str ( ) ) ;
2022-06-11 09:54:04 +00:00
HGBase_DeleteFile ( oldFileName ) ;
char fileName [ 256 ] ;
2022-06-13 04:02:51 +00:00
sprintf ( fileName , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + imageIndex , imgFmt . c_str ( ) ) ;
2022-06-11 09:54:04 +00:00
SaveToFile ( imgData , imgSize , fileName ) ;
}
void ManagerV2 : : DeleteBindFolderImage ( const std : : vector < BatchTableInfo > & tables , const std : : vector < int > & imageIndexList )
{
assert ( ! m_bindFolder . empty ( ) ) ;
2022-06-13 04:02:51 +00:00
char fmt [ 24 ] ;
sprintf ( fmt , " %%s%%0%dd.%%s " , m_bindNameWidth ) ;
2022-06-11 09:54:04 +00:00
for ( int i = 0 ; i < ( int ) imageIndexList . size ( ) ; + + i )
{
2022-06-22 12:38:39 +00:00
int idx = imageIndexList [ i ] ;
char fileName [ 256 ] ;
sprintf ( fileName , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + idx , tables [ idx ] . format . c_str ( ) ) ;
HGBase_DeleteFile ( fileName ) ;
2022-06-11 09:54:04 +00:00
}
int value = 0 ;
for ( int i = 0 ; i < ( int ) tables . size ( ) ; + + i )
{
bool find = false ;
for ( int j = 0 ; j < ( int ) imageIndexList . size ( ) ; + + j )
{
2022-06-22 12:38:39 +00:00
if ( i = = imageIndexList [ j ] )
2022-06-11 09:54:04 +00:00
{
find = true ;
break ;
}
}
if ( find )
{
+ + value ;
}
else
{
if ( value > 0 )
{
char fileName [ 256 ] ;
2022-06-22 12:38:39 +00:00
sprintf ( fileName , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + i , tables [ i ] . format . c_str ( ) ) ;
2022-06-11 09:54:04 +00:00
char destName [ 256 ] ;
2022-06-22 12:38:39 +00:00
sprintf ( destName , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + i - value , tables [ i ] . format . c_str ( ) ) ;
2022-06-14 10:43:40 +00:00
# if defined(HG_CMP_MSC)
2022-06-15 01:50:21 +00:00
MoveFileA ( fileName , destName ) ;
2022-06-14 10:43:40 +00:00
# else
2022-06-15 01:50:21 +00:00
rename ( fileName , destName ) ;
2022-06-14 10:43:40 +00:00
# endif
2022-06-11 09:54:04 +00:00
}
}
}
}
void ManagerV2 : : ExchangeBindFolderImage ( const std : : vector < BatchTableInfo > & tables , int imageIndex1 , int imageIndex2 )
{
assert ( ! m_bindFolder . empty ( ) ) ;
2022-06-13 04:02:51 +00:00
char fmt [ 24 ] ;
sprintf ( fmt , " %%s%%0%dd.%%s " , m_bindNameWidth ) ;
2022-06-22 12:38:39 +00:00
std : : string format1 = tables [ imageIndex1 ] . format ;
std : : string format2 = tables [ imageIndex2 ] . format ;
2022-06-11 09:54:04 +00:00
char fileName1 [ 256 ] ;
2022-06-13 04:02:51 +00:00
sprintf ( fileName1 , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + imageIndex1 , format1 . c_str ( ) ) ;
2022-06-11 09:54:04 +00:00
char TmpFileName [ 256 ] ;
sprintf ( TmpFileName , " %sTemp " , m_bindFolder . c_str ( ) ) ;
2022-06-14 10:43:40 +00:00
# if defined(HG_CMP_MSC)
MoveFileA ( fileName1 , TmpFileName ) ;
# else
rename ( fileName1 , TmpFileName ) ;
# endif
2022-06-11 09:54:04 +00:00
char fileName2 [ 256 ] ;
2022-06-13 04:02:51 +00:00
sprintf ( fileName2 , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + imageIndex2 , format2 . c_str ( ) ) ;
2022-06-11 09:54:04 +00:00
char fileName2Dest [ 256 ] ;
2022-06-13 04:02:51 +00:00
sprintf ( fileName2Dest , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + imageIndex1 , format2 . c_str ( ) ) ;
2022-06-14 10:43:40 +00:00
# if defined(HG_CMP_MSC)
MoveFileA ( fileName2 , fileName2Dest ) ;
# else
rename ( fileName2 , fileName2Dest ) ;
# endif
2022-06-11 09:54:04 +00:00
char fileName1Dest [ 256 ] ;
2022-06-13 04:02:51 +00:00
sprintf ( fileName1Dest , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + imageIndex2 , format1 . c_str ( ) ) ;
2022-06-14 10:43:40 +00:00
# if defined(HG_CMP_MSC)
MoveFileA ( TmpFileName , fileName1Dest ) ;
# else
rename ( TmpFileName , fileName1Dest ) ;
# endif
2022-06-11 09:54:04 +00:00
}
2022-06-13 04:02:51 +00:00
void ManagerV2 : : ClearBindFolderImageList ( const std : : vector < BatchTableInfo > & tables )
2022-06-11 06:18:33 +00:00
{
assert ( ! m_bindFolder . empty ( ) ) ;
2022-06-13 04:02:51 +00:00
char fmt [ 24 ] ;
sprintf ( fmt , " %%s%%0%dd.%%s " , m_bindNameWidth ) ;
2022-06-11 06:18:33 +00:00
2022-06-13 04:02:51 +00:00
for ( int i = 0 ; i < ( int ) tables . size ( ) ; + + i )
2022-06-11 06:18:33 +00:00
{
2022-06-13 04:02:51 +00:00
char fileName [ 256 ] ;
2022-06-22 12:38:39 +00:00
sprintf ( fileName , fmt , m_bindFolder . c_str ( ) , m_bindNameBase + i , tables [ i ] . format . c_str ( ) ) ;
2022-06-13 04:02:51 +00:00
HGBase_DeleteFile ( fileName ) ;
}
2022-06-11 06:18:33 +00:00
}
2023-11-14 04:38:12 +00:00
HGUInt ManagerV2 : : GetDpi ( )
{
HGUInt dpi = 200 ;
SANE_Int num_dev_options = 0 ;
sane_control_option ( m_devHandle , 0 , SANE_ACTION_GET_VALUE , & num_dev_options , nullptr ) ;
for ( int i = 1 ; i < num_dev_options ; + + i )
{
const SANE_Option_Descriptor * desp = sane_get_option_descriptor ( m_devHandle , i ) ;
if ( nullptr = = desp )
continue ;
if ( SANE_TYPE_INT = = desp - > type )
{
SANE_Int value = 0 ;
sane_control_option ( m_devHandle , i , SANE_ACTION_GET_VALUE , & value , nullptr ) ;
if ( 0 = = strcmp ( desp - > name , SANE_STD_OPT_NAME_RESOLUTION ) )
{
dpi = ( HGUInt ) value ;
}
}
}
return dpi ;
}
2022-05-30 11:01:23 +00:00
int ManagerV2 : : sane_ex_callback ( SANE_Handle hdev , int code , void * data , unsigned int * len , void * param )
{
( void ) hdev ;
( void ) len ;
ManagerV2 * p = ( ManagerV2 * ) param ;
switch ( code )
{
case SANE_EVENT_DEVICE_ARRIVED :
{
SANE_Device * sane_dev = ( SANE_Device * ) data ;
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " SANE_EVENT_DEVICE_ARRIVED, name=%s " , Utf8ToStdString ( sane_dev - > name ) . c_str ( ) ) ;
HGBase_EnterLock ( p - > m_lock ) ;
2023-05-16 07:37:40 +00:00
std : : list < class WSUser * > : : iterator iter ;
for ( iter = p - > m_user . begin ( ) ; iter ! = p - > m_user . end ( ) ; + + iter )
{
2024-04-18 03:04:35 +00:00
WSUser : : DbtEvent ( p - > m_initIden , p - > m_initHaveIden , SANEEVENT_ARRIVE , sane_dev - > name , false , * iter ) ;
2023-05-16 07:37:40 +00:00
}
2022-05-30 11:01:23 +00:00
HGBase_LeaveLock ( p - > m_lock ) ;
}
break ;
case SANE_EVENT_DEVICE_LEFT :
{
SANE_Device * sane_dev = ( SANE_Device * ) data ;
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " SANE_EVENT_DEVICE_LEFT, name=%s " , Utf8ToStdString ( sane_dev - > name ) . c_str ( ) ) ;
2022-06-01 10:36:22 +00:00
CloseDevParam * closeDevParam = new CloseDevParam ;
closeDevParam - > mgr = p ;
closeDevParam - > devName = sane_dev - > name ;
HGMsg msg ;
msg . id = MSGID_CLOSE_DEVICE ;
msg . data = closeDevParam ;
if ( HGBASE_ERR_OK ! = HGBase_PostPumpMessage ( p - > m_msgPump , & msg ) )
{
delete closeDevParam ;
}
2022-05-30 11:01:23 +00:00
HGBase_EnterLock ( p - > m_lock ) ;
2023-05-16 07:37:40 +00:00
std : : list < class WSUser * > : : iterator iter ;
for ( iter = p - > m_user . begin ( ) ; iter ! = p - > m_user . end ( ) ; + + iter )
{
2024-04-18 03:04:35 +00:00
WSUser : : DbtEvent ( p - > m_initIden , p - > m_initHaveIden , SANEEVENT_REMOVE , sane_dev - > name , false , * iter ) ;
2023-05-16 07:37:40 +00:00
}
2022-05-30 11:01:23 +00:00
HGBase_LeaveLock ( p - > m_lock ) ;
}
break ;
case SANE_EVENT_WORKING :
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " SANE_EVENT_WORKING, msg=%s " , Utf8ToStdString ( ( char * ) data ) . c_str ( ) ) ;
HGBase_EnterLock ( p - > m_lock ) ;
2024-04-18 07:39:23 +00:00
if ( NULL ! = p - > m_scanUser )
2023-05-16 07:37:40 +00:00
{
2024-04-18 07:39:23 +00:00
WSUser : : SaneEvent ( p - > m_scanIden , p - > m_scanHaveIden , SANEEVENT_WORKING , ( const char * ) data , false , p - > m_scanUser ) ;
2023-05-16 07:37:40 +00:00
}
2022-05-30 11:01:23 +00:00
HGBase_LeaveLock ( p - > m_lock ) ;
}
break ;
case SANE_EVENT_SCAN_FINISHED :
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " SANE_EVENT_SCAN_FINISHED, msg=%s " , Utf8ToStdString ( ( char * ) data ) . c_str ( ) ) ;
2022-06-01 10:36:22 +00:00
HGBase_SetEvent ( p - > m_scanEvent ) ;
2022-06-06 11:34:54 +00:00
ScanFinishParam * scanFinishParam = new ScanFinishParam ;
scanFinishParam - > mgr = p ;
HGMsg msg ;
msg . id = MSGID_SCAN_FINISH ;
msg . data = scanFinishParam ;
if ( HGBASE_ERR_OK ! = HGBase_PostPumpMessage ( p - > m_msgPump , & msg ) )
{
delete scanFinishParam ;
}
2022-05-30 11:01:23 +00:00
HGBase_EnterLock ( p - > m_lock ) ;
2024-04-18 07:39:23 +00:00
if ( NULL ! = p - > m_scanUser )
2023-05-16 07:37:40 +00:00
{
2024-04-18 07:39:23 +00:00
WSUser : : SaneEvent ( p - > m_scanIden , p - > m_scanHaveIden , SANEEVENT_FINISH , ( const char * ) data , ( 0 ! = * len ) , p - > m_scanUser ) ;
2023-05-16 07:37:40 +00:00
}
2022-05-30 11:01:23 +00:00
HGBase_LeaveLock ( p - > m_lock ) ;
}
break ;
case SANE_EVENT_STATUS :
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " SANE_EVENT_STATUS, msg=%s " , Utf8ToStdString ( ( char * ) data ) . c_str ( ) ) ;
HGBase_EnterLock ( p - > m_lock ) ;
2024-04-18 07:39:23 +00:00
if ( NULL ! = p - > m_scanUser )
2023-05-16 07:37:40 +00:00
{
2024-04-18 07:39:23 +00:00
WSUser : : SaneEvent ( p - > m_scanIden , p - > m_scanHaveIden , SANEEVENT_STATUS , ( const char * ) data , false , p - > m_scanUser ) ;
2023-05-16 07:37:40 +00:00
}
2022-05-30 11:01:23 +00:00
HGBase_LeaveLock ( p - > m_lock ) ;
}
break ;
case SANE_EVENT_ERROR :
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " SANE_EVENT_ERROR, msg=%s " , Utf8ToStdString ( ( char * ) data ) . c_str ( ) ) ;
HGBase_EnterLock ( p - > m_lock ) ;
2024-04-18 07:39:23 +00:00
if ( NULL ! = p - > m_scanUser )
2023-05-16 07:37:40 +00:00
{
2024-04-18 07:39:23 +00:00
WSUser : : SaneEvent ( p - > m_scanIden , p - > m_scanHaveIden , SANEEVENT_ERROR , ( const char * ) data , ( 0 ! = * len ) , p - > m_scanUser ) ;
2023-05-16 07:37:40 +00:00
}
2022-05-30 11:01:23 +00:00
HGBase_LeaveLock ( p - > m_lock ) ;
}
break ;
case SANE_EVENT_IMAGE_OK :
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " SANE_EVENT_IMAGE_OK " ) ;
SANE_Image * sane_img = ( SANE_Image * ) data ;
HGUInt imgType = 0 ;
if ( sane_img - > header . format = = SANE_FRAME_GRAY )
{
if ( 1 = = sane_img - > header . depth )
imgType = HGBASE_IMGTYPE_BINARY ;
else if ( 8 = = sane_img - > header . depth )
imgType = HGBASE_IMGTYPE_GRAY ;
}
else if ( sane_img - > header . format = = SANE_FRAME_RGB )
imgType = HGBASE_IMGTYPE_RGB ;
HGByte * data = sane_img - > data ;
HGImageInfo imgInfo = { ( HGUInt ) sane_img - > header . pixels_per_line , ( HGUInt ) sane_img - > header . lines ,
imgType , ( HGUInt ) sane_img - > header . bytes_per_line , HGBASE_IMGORIGIN_TOP } ;
HGImage img = NULL ;
HGBase_CreateImageFromData ( data , & imgInfo , NULL , 0 , HGBASE_IMGORIGIN_TOP , & img ) ;
if ( NULL ! = img )
{
2024-04-23 09:50:11 +00:00
p - > m_curImgIndex + + ;
2023-11-14 04:38:12 +00:00
HGBase_SetImageDpi ( img , p - > m_dpi , p - > m_dpi ) ;
2022-06-01 10:36:22 +00:00
HGBase_EnterLock ( p - > m_lock ) ;
std : : string imagePath ;
2024-04-18 03:04:35 +00:00
int ret = p - > SaveImage ( img , ! p - > m_scanLocalSave , imagePath ) ;
2022-06-01 10:36:22 +00:00
if ( 0 = = ret )
2022-05-30 11:01:23 +00:00
{
2024-04-18 03:27:36 +00:00
HGBool blank = HGFALSE ;
if ( p - > m_scanBlankCheck )
2024-04-18 07:39:23 +00:00
{
2024-04-18 03:27:36 +00:00
HGImgProc_ImageBlankCheck ( img , NULL , & blank ) ;
2024-04-18 07:39:23 +00:00
}
std : : string path ;
if ( p - > m_scanLocalSave )
{
AddSavedFileParam * addParam = new AddSavedFileParam ;
addParam - > mgr = p ;
addParam - > fileName = imagePath ;
HGMsg msg ;
msg . id = MSGID_ADD_SAVEDFILE ;
msg . data = addParam ;
if ( HGBASE_ERR_OK ! = HGBase_PostPumpMessage ( p - > m_msgPump , & msg ) )
{
delete addParam ;
}
path = imagePath ;
}
std : : string base64 ;
if ( p - > m_scanGetBase64 )
{
std : : string errInfo ;
p - > LoadLocalImage ( imagePath . c_str ( ) , base64 , errInfo ) ;
}
2024-04-18 03:27:36 +00:00
2024-04-18 07:39:23 +00:00
if ( NULL ! = p - > m_scanUser )
2023-05-16 07:37:40 +00:00
{
2024-04-18 03:04:35 +00:00
WSUser : : SaneImageCallback ( p - > m_scanIden , p - > m_scanHaveIden , p - > m_scanBlankCheck , p - > m_scanLocalSave , p - > m_scanGetBase64 ,
2024-04-18 07:39:23 +00:00
blank ? true : false , path . c_str ( ) , base64 . c_str ( ) , p - > m_scanUser ) ;
2023-05-16 07:37:40 +00:00
}
2024-04-18 01:51:58 +00:00
2024-04-18 03:04:35 +00:00
if ( ! p - > m_scanLocalSave )
2024-04-18 01:51:58 +00:00
{
HGBase_DeleteFile ( imagePath . c_str ( ) ) ;
}
2022-05-30 11:01:23 +00:00
}
2022-06-01 10:36:22 +00:00
HGBase_LeaveLock ( p - > m_lock ) ;
2022-05-30 11:01:23 +00:00
HGBase_DestroyImage ( img ) ;
}
}
break ;
}
return 0 ;
2022-05-23 10:29:23 +00:00
}
2023-05-17 07:37:04 +00:00
void HGAPI ManagerV2 : : ThreadFunc ( HGThread thread , HGPointer param )
{
ManagerV2 * p = ( ManagerV2 * ) param ;
while ( ! p - > m_stopThread )
{
HGBase_EnterLock ( p - > m_lock ) ;
HGUInt timeout = p - > m_timeout ;
HGBase_LeaveLock ( p - > m_lock ) ;
HGResult ret = HGBase_WaitEventTimeout ( p - > m_event , timeout ) ;
if ( HGBASE_ERR_TIMEOUT = = ret )
{
HGBase_WriteInfo ( HGBASE_INFOTYPE_DESC , " timeout, deinit device " ) ;
DeinitDevParam * deinitDevParam = new DeinitDevParam ;
deinitDevParam - > mgr = p ;
HGMsg msg ;
msg . id = MSGID_DEINIT_DEVICE ;
msg . data = deinitDevParam ;
if ( HGBASE_ERR_OK ! = HGBase_PostPumpMessage ( p - > m_msgPump , & msg ) )
{
delete deinitDevParam ;
}
}
}
}
2022-05-23 10:29:23 +00:00
}