|
本帖最后由 henices 于 2017-10-17 13:58 编辑
# o8 e1 I8 l% a, l, Z- H- @$ N, A* n& Z- h
http://www.pdawiki.com/forum/thread-21902-1-1.html [GoldenDict] 如何查看 GoldenDict 下某部词典的 ID ?
' f a/ o: X0 [& ~/ u
/ E; `' b- n8 O( S
- w) v* U6 m" }9 ?2 u" G
3 X# A* L+ p) V0 U8 u2 ^- <dictionary name="21**大英汉词典">139305d43503a41a44ebf590fd8f3fae</dictionary>
) E. {; |* G; g6 g- H - , P& K! M! w7 G) U! W( e- p0 S
- >>> import hashlib
! K# [, z+ `7 D0 D' v& Q - >>> hashlib.md5('/home/henices/dictionary/21/21.mdd\0/home/henices/dictionary/21/21.mdx\0').hexdigest()
6 {2 Y2 P) k, K5 K" k% {! M - '139305d43503a41a44ebf590fd8f3fae'! B3 D$ M% l: o( r' \
复制代码 3 d- G5 f# \& g% u" f0 z; ]
! ^: M2 K+ P. u! u使用的是 md5 哈希, 参见 dictionary.cc -> makeDictionaryId8 D* i- n: t- d7 y# N. b; d
2 B, I: e4 K/ o: W- % P7 c6 g7 w0 R- C2 [
- string makeDictionaryId( vector< string > const & dictionaryFiles ) throw() 3 H' J+ p7 N9 p8 s1 y+ k
- { 0 P0 w. B4 I$ ^3 P" U; q* S3 q
- std::vector< string > sortedList; - |$ }+ z, r7 i: r
-
8 i: n9 m2 Q; s9 e. q. W W - if ( Config::isPortableVersion() ) R6 y1 `$ |2 {6 ]8 Z4 s N9 U
- { ) [! i; N1 k: p
- // For portable version, we use relative paths
3 o4 T ?- \* E; X - sortedList.reserve( dictionaryFiles.size() );
+ {* R5 I I4 T: L2 _ -
" x$ Q5 `1 t6 `" j - QDir dictionariesDir( Config::getPortableVersionDictionaryDir() ); ( d3 w9 q) u" W/ s- l" e
-
! P/ z# C* X9 {3 { - for( unsigned x = 0; x < dictionaryFiles.size(); ++x )
1 N2 J; j/ D% _2 p, d7 N/ f) J - {
5 z7 r1 ~9 v H% W - string const & full( dictionaryFiles[ x ] );
( A Q9 [5 o; G% W% f - - X- s9 v& Q+ Z- }( e& H! {6 _' u
- QFileInfo fileInfo( FsEncoding::decode( full.c_str() ) ); 8 a( v+ W6 F) q
-
% K9 V; g: ]4 }0 J - if ( fileInfo.isAbsolute() )
5 ]% ^( l, u# R5 {6 u! T6 e - sortedList.push_back( FsEncoding::encode( dictionariesDir.relativeFilePath( fileInfo.filePath() ) ) ); + y! }3 v* U% ? g9 d; v
- else ; L2 m J9 z* Y5 }& w R, m' m
- { 7 l! o1 d+ e Z0 [$ t
- // Well, it's relative. We don't technically support those, but
4 j$ S4 K4 R; O% }4 E - // what the heck
( k% Q4 |* M# _3 V( v - sortedList.push_back( full );
4 `6 E2 ?4 G" {1 a8 i. b4 q, R) r `0 | - } 2 Q) H* X1 u# F% H
- }
! _7 R1 z5 O0 l - }
5 K8 V3 m( ~" z; U, @ - else
3 `3 x5 x6 e" ^7 x8 l - sortedList = dictionaryFiles;
; L. l8 D( q8 x9 |3 V -
# X5 P* B Y( X - std::sort( sortedList.begin(), sortedList.end() );
- K2 r; [# E3 X4 { - ; u3 R$ l( u- [( J, K u: C
- QCryptographicHash hash( QCryptographicHash::Md5 ); 7 q# E* K) I$ [% D$ H; C
- / g/ a( g5 E9 z1 f! y( j0 s
- for( std::vector< string >::const_iterator i = sortedList.begin(); . C# A) w2 Z0 o# o6 {7 v0 \
- i != sortedList.end(); ++i )
5 h/ e/ Z6 T' ^5 E* V - hash.addData( i->c_str(), i->size() + 1 );
# T3 l0 E; Z1 d$ H+ D& @ - 3 s2 R$ ^) S4 y- D$ u
- return hash.result().toHex().data();
V5 Y {3 W# d; H# i8 ?. V$ m - } 1 e+ }; f, E) q' n. Q
复制代码
+ l9 Y' n% c! F& T" T# K! l2 P; ~. R) F: l$ R2 k. D
" c8 J0 T/ d9 h2 k- I5 d' @- ~
各种来源的 ID 是随机生成的 (website/wiki/program/...): R7 h7 x( z/ w4 V. s$ t& z9 W
: t9 y9 i# e/ P, }0 [% `2 B% z
sources.cc4 R$ p/ a* W0 P, o$ q" ]( ?
. j; u% Z3 e7 v% ^% s- void ProgramsModel::addNewProgram()
0 }& J3 q2 l" ^0 t/ R+ h - {
% Z- E) ]& x- ~0 ^" I8 ~8 y - Config::Program p;
' X5 Y( b" N( u0 v! k6 d8 i -
- C/ d+ S; a1 j; y6 U3 N% Z - p.enabled = false;
* Z' }5 R& \7 I$ u' b; W5 X* d - p.type = Config::Program::Audio; - w7 C7 c6 }8 m, d, h& ^
- 9 [$ s1 J" E, g) M: Q, e
- p.id = Dictionary::generateRandomDictionaryId();
# N b# I% B- ~+ O P/ L -
$ t: X7 {8 L/ B/ P3 { - beginInsertRows( QModelIndex(), programs.size(), programs.size() ); * s1 b; o/ n! f- \9 O, v& S) u
- programs.push_back( p ); 0 @) g l; `' H4 f, O
- endInsertRows();
, n+ `& ?; g* j; i. O% }/ a; M - } ; r# c# H8 f3 g, Z" n& d
复制代码 9 R" K8 p+ L5 ~- E( V9 e+ b
0 ]$ q! b0 v( g f0 d" adictionary.cc
M' x6 U, p0 t! G% G- X
+ T& ? d. p; k5 \) A0 V- QString generateRandomDictionaryId() - H/ C7 S+ @7 P) V% o* A
- {
- C" ^1 i+ J9 {4 l0 S - return QString(
( m0 o3 l. O U8 N" a0 H# k - QCryptographicHash::hash( + w5 c3 O' B" }: ?, n I+ }
- QDateTime::currentDateTime().toString( ""Random"dd.MM.yyyy hh:mm:ss.zzz" ).toUtf8(), : Z6 z% l7 O; f3 U9 F
- QCryptographicHash::Md5 ).toHex() ); 6 N- j& r& t7 O/ g! S9 k
- }
4 c4 R: h# P) h( _* p* F7 C. K7 z* K
复制代码
3 t. s7 A- o [% |7 O# L7 N |
评分
-
5
查看全部评分
-
|