|
|
本帖最后由 henices 于 2017-10-17 13:58 编辑
. K* C9 |) o8 A* @" j
4 {5 s; D+ S) Y1 hhttp://www.pdawiki.com/forum/thread-21902-1-1.html [GoldenDict] 如何查看 GoldenDict 下某部词典的 ID ?0 Z* ~" Z8 C0 p9 ?) b/ l
, s- _! M# q0 s7 Z- r3 A
! R& X6 ^5 ~' T N3 G
- 6 K' f( {* j. G
- <dictionary name="21**大英汉词典">139305d43503a41a44ebf590fd8f3fae</dictionary>5 z- Z+ u, E. F3 u
- % F8 r% V. m% P
- >>> import hashlib
% F- B" W- g7 z/ H% ?. [ - >>> hashlib.md5('/home/henices/dictionary/21/21.mdd\0/home/henices/dictionary/21/21.mdx\0').hexdigest()
" S! L1 o/ Q% [/ E" p i - '139305d43503a41a44ebf590fd8f3fae'
) J" S. @5 i# W
复制代码
" i. C6 S) F! ]9 ?. W$ m7 }9 L6 C d9 X" D& e6 d1 u
使用的是 md5 哈希, 参见 dictionary.cc -> makeDictionaryId5 X" K e. H6 _7 ~) n+ p' |
?" g2 k) ~0 p; D7 Q! |* d
$ l R; u; \5 W; w- string makeDictionaryId( vector< string > const & dictionaryFiles ) throw() # s( b+ o r* M7 Z) ~/ R
- {
3 n0 h" n) O$ l - std::vector< string > sortedList; 2 z$ D8 k' g, o: ?$ Z8 ?
-
) d( ]* _$ u9 y - if ( Config::isPortableVersion() )
& m6 W) q9 M. Y, u+ E6 b- m8 U - { 4 W! n- q6 W: k6 n+ f* ^0 T
- // For portable version, we use relative paths - [8 w2 U S+ j' \2 Y+ q
- sortedList.reserve( dictionaryFiles.size() );
% _$ |# f" g" _# o6 p, I( B9 d - , ]$ x$ I" N% q L% k7 f6 b
- QDir dictionariesDir( Config::getPortableVersionDictionaryDir() );
0 ^7 J. {! Z; |0 r* F0 h* q - 7 `& @ r+ {6 y3 }% [* t$ E
- for( unsigned x = 0; x < dictionaryFiles.size(); ++x ) : k# J7 `% l2 i$ i7 B4 V
- { . ]. G& H) R9 T
- string const & full( dictionaryFiles[ x ] );
$ T6 |4 x( M/ E( j# ]3 K$ f- f/ j3 j - 7 @/ O7 `& Q+ k& F
- QFileInfo fileInfo( FsEncoding::decode( full.c_str() ) ); 2 g* u1 k4 j5 L3 v5 a) b9 C
-
& U) v* U1 g" Z% Z$ G& r6 H P - if ( fileInfo.isAbsolute() )
9 L' n& i$ i% k q( @8 X - sortedList.push_back( FsEncoding::encode( dictionariesDir.relativeFilePath( fileInfo.filePath() ) ) );
# a5 l( ]/ Y- V z - else ; b8 k/ Y/ H( T9 k/ S) M0 g, R
- { + Z# n7 C% ~2 h* H, e5 d
- // Well, it's relative. We don't technically support those, but # T( ^5 N8 B& e: V0 N
- // what the heck
# j( L R2 l3 S3 _ - sortedList.push_back( full );
% @/ x4 h% `& g5 t - } l+ I- T: \& E
- }
: {9 m, _% l$ ?% K - }
* z- k$ |, A- M& @4 k - else : w S9 s1 c: n- J r
- sortedList = dictionaryFiles; - Y/ o: U( F' Q( B7 t
-
P4 M( f- d8 x! I% {* m% D: N; T - std::sort( sortedList.begin(), sortedList.end() );
, S- ] Y: J4 b0 _, V X -
) K$ ^' n. ~* p5 D% M3 x# f - QCryptographicHash hash( QCryptographicHash::Md5 ); / w" l; t" Q* }/ i0 M
- : k' c; Y* C% F% U* }
- for( std::vector< string >::const_iterator i = sortedList.begin(); 3 R( I* a: g6 Q e) R
- i != sortedList.end(); ++i )
5 r2 j, S- E& e( Z7 g# l1 i - hash.addData( i->c_str(), i->size() + 1 ); 4 g6 ]# A% k" r6 `- {6 o
-
* I" R C% U/ n - return hash.result().toHex().data(); 6 N0 @6 l3 N: P9 |; x, l4 t
- } & Z6 K Z( f+ a+ ^; f) X: Y
复制代码
7 ^+ r5 j8 ?* E/ y4 ?7 |) y' d: X# ?
4 L: T3 V: `6 t3 n各种来源的 ID 是随机生成的 (website/wiki/program/...)8 b4 n, T, B T( h
8 |* e& U% B; O- P
sources.cc
) ` M0 A, q" y9 a$ G( k- & K. C3 D% [* g- o" ^( M
- void ProgramsModel::addNewProgram() - Z( g( M( j$ e: w3 a- }2 K3 W
- {
, P' \0 {3 j7 B - Config::Program p; 0 G! n- U# r- A: E3 ~0 \ P
-
# v! u; _. q, J7 x; u - p.enabled = false; P8 O$ s9 P" ^7 R" q4 J
- p.type = Config::Program::Audio; 8 w2 j5 j* Q, m/ @& i7 V; }. J
-
* q5 x2 k! Q, W - p.id = Dictionary::generateRandomDictionaryId(); . S* c- A* J% w
-
& H/ q" j7 Q: U2 u J- h/ t# H - beginInsertRows( QModelIndex(), programs.size(), programs.size() ); . ^1 H$ d, e! U1 S. _) J) z
- programs.push_back( p ); ' t9 z; P4 k8 r- E' U# i
- endInsertRows(); % g" `, M3 v& u5 G
- } * d; T' x3 j" E+ n# c7 k
复制代码
2 h1 Y9 l! k/ J+ u4 w0 q
$ p. P7 A7 g& R5 h& Kdictionary.cc
% [' ]# `. k' |2 p1 x: o- 4 D1 H# i, W/ J! [ n
- QString generateRandomDictionaryId()
9 l2 E0 e, H2 r0 q - {
$ T2 a/ W/ |7 G - return QString( 0 x+ r/ {) J7 ^; M0 x' v" s
- QCryptographicHash::hash(
* Z) @" h( Q. \7 v9 E4 N - QDateTime::currentDateTime().toString( ""Random"dd.MM.yyyy hh:mm:ss.zzz" ).toUtf8(), % x$ l; Q! q: n# a
- QCryptographicHash::Md5 ).toHex() ); ! g. g1 R2 t, P
- } & V/ O0 b. {* n
复制代码
/ _- F$ i* G, |6 ~" I1 V, S1 B I |
评分
-
5
查看全部评分
-
|