|
本帖最后由 henices 于 2017-10-17 13:58 编辑 " b+ z) `0 G5 Y* y& c! G4 }9 ~
: D l# j+ n& ^5 t" c! S/ Ahttp://www.pdawiki.com/forum/thread-21902-1-1.html [GoldenDict] 如何查看 GoldenDict 下某部词典的 ID ?9 H4 v* e) F. g' s! C" @: l# ^
9 M o/ F% Q" o
1 x4 m; c8 f( }$ j2 N* Z; r
* W$ A- B& t. P- <dictionary name="21**大英汉词典">139305d43503a41a44ebf590fd8f3fae</dictionary>! ]$ g% `! |) L9 U3 [' V
) L5 p' |5 `7 H4 D2 R- >>> import hashlib 9 s. K ^2 W' I* ^( F7 q' L
- >>> hashlib.md5('/home/henices/dictionary/21/21.mdd\0/home/henices/dictionary/21/21.mdx\0').hexdigest()
+ Y( @9 N/ B3 @4 R - '139305d43503a41a44ebf590fd8f3fae'; X" a0 [8 W. l& t; E" z
复制代码
4 k6 U- p1 Y. f
4 D: J3 i: E1 o* N$ h# p9 y使用的是 md5 哈希, 参见 dictionary.cc -> makeDictionaryId8 n* X( j! z: a1 r; E1 X: E9 u/ ~
: {' Q, Z" }( |% w, `
2 F R! k# d+ ~ Z5 P2 `" _- string makeDictionaryId( vector< string > const & dictionaryFiles ) throw()
8 e. q! \! X/ K+ y: j: L - {
# y3 V O4 V7 ?8 T8 j& h - std::vector< string > sortedList; ! h, s$ V5 Y9 C' L
-
9 v) k( t3 C, N) ` - if ( Config::isPortableVersion() )
$ F5 `6 l8 X/ p2 A9 ] - { - {/ J3 Z# A3 `2 l5 {: G
- // For portable version, we use relative paths
3 X7 [ R1 Z. n* x - sortedList.reserve( dictionaryFiles.size() );
8 [5 @2 l" ^ c; n8 r: a - 9 s" n1 _7 ?. P1 e+ b
- QDir dictionariesDir( Config::getPortableVersionDictionaryDir() ); 7 Z- @( F) _- F( [
-
% b: w, U5 n/ P5 E' d6 q - for( unsigned x = 0; x < dictionaryFiles.size(); ++x )
" p+ H. V* h- D0 R - { ' Q1 b- A: Y# L
- string const & full( dictionaryFiles[ x ] ); - u. v0 Z* U2 N* t4 k
- 7 U3 d: G; X3 E3 P; n
- QFileInfo fileInfo( FsEncoding::decode( full.c_str() ) ); 0 v0 D5 }) d/ M Q( A) G
-
) e5 ]+ ^/ R% `1 W - if ( fileInfo.isAbsolute() ) 8 [$ y5 U: n( L; G
- sortedList.push_back( FsEncoding::encode( dictionariesDir.relativeFilePath( fileInfo.filePath() ) ) ); ! _$ w2 I# K, G0 p7 W$ G; j( h$ Q: Y
- else
9 {2 @7 H1 B: j0 J; Q - {
2 d+ f. @( n* s+ [) {: T0 D - // Well, it's relative. We don't technically support those, but 0 k! c. k7 M* S5 e! q
- // what the heck
- s1 l4 T! |0 \4 \; ^! j4 l - sortedList.push_back( full ); % F' C" n0 s) f0 I" K
- } : ` g9 O# f( d4 d1 B2 W4 N
- }
3 K% |. U6 h8 Z% e7 F! i) ^! w5 Y6 V - } ! T, t4 _, s) }3 n& e$ }
- else
, X! G( f5 P) q+ G* j/ z; W1 J - sortedList = dictionaryFiles;
6 e' J# O' _4 T( u4 K ^8 B - , d2 P3 \9 b; I1 R
- std::sort( sortedList.begin(), sortedList.end() );
2 ?7 v! P" C& y5 p - : b) r8 E. ]9 }2 ?+ s, W
- QCryptographicHash hash( QCryptographicHash::Md5 );
' D( D; g% H( i2 W8 w" ], m/ I -
9 ^2 O; I8 K7 B* g2 U1 i4 c - for( std::vector< string >::const_iterator i = sortedList.begin(); # W" W, A( v. }! j3 v, K8 z
- i != sortedList.end(); ++i ) 5 o% Z: |, D- f( |7 q
- hash.addData( i->c_str(), i->size() + 1 ); 4 T9 n' T3 f( Z" u8 m' P
-
7 \) r5 k: w) Z; {8 x* Y; h - return hash.result().toHex().data(); : u) B/ G2 y' t! S6 H! y6 g* C5 Z
- } ; I9 y7 k! J# o* v- ?! T
复制代码 * a& z) ?7 f- B% c M
( [* U) C+ n% I$ Y" {# |6 O
8 f4 U( S1 ~) I+ R, i$ G, X各种来源的 ID 是随机生成的 (website/wiki/program/...)
* M$ z# x5 N0 E7 ?7 u( h
0 t2 w# X$ ?9 ]- q2 G; m+ C8 msources.cc6 P# L' X, t' ^
- A& n8 t7 w3 p" l- void ProgramsModel::addNewProgram()
8 |/ c o( A2 X8 ?. |8 ` - { 2 u9 Z h, X, Q3 G! P) F) d- W
- Config::Program p;
1 h; L3 P; K( e( z; j - 7 Y1 L9 ~; J* I5 s+ W, u
- p.enabled = false;
2 ~) U- e6 l3 ?9 c: T - p.type = Config::Program::Audio; & M/ E+ G2 e8 E
-
7 F7 G- ]- I0 u* e - p.id = Dictionary::generateRandomDictionaryId();
: P& v* C( p! u- d - 4 D% s& j. D& j5 x
- beginInsertRows( QModelIndex(), programs.size(), programs.size() );
& j1 X9 X7 R$ X3 Y# K - programs.push_back( p );
. M9 `5 c+ d) Z9 Q - endInsertRows();
* q3 ` B7 m3 ?! j8 ]8 e- y - }
3 Y0 `' J% O7 i( E" P! N
复制代码 ; g/ @9 M. w# a
7 W8 `6 V" D! ~. N3 C5 F
dictionary.cc 3 N$ U5 e6 {9 }, l2 K# E
- * P! j6 q1 c. @7 Q& s
- QString generateRandomDictionaryId()
( h7 H9 V' k" p, I$ t - {
) v% B: A! ?3 y; r - return QString( ' z0 H: L, S9 f0 ~. k
- QCryptographicHash::hash(
3 K# H8 Z7 [5 Y; _; y - QDateTime::currentDateTime().toString( ""Random"dd.MM.yyyy hh:mm:ss.zzz" ).toUtf8(),
$ v+ A- q& N2 ] - QCryptographicHash::Md5 ).toHex() ); 5 w$ P% }9 `3 _$ [0 O# a, Z
- } 6 A! B4 t X8 c) s, a p; g. ]8 A
复制代码
; t9 C/ F; x; K |
评分
-
5
查看全部评分
-
|