|
本帖最后由 henices 于 2017-10-17 13:58 编辑
1 k- S6 k: ~6 `. V6 j4 Y7 Y& [/ F' _3 w( O
http://www.pdawiki.com/forum/thread-21902-1-1.html [GoldenDict] 如何查看 GoldenDict 下某部词典的 ID ?
) M5 }3 o2 S9 R( T y
% S2 m, i- Q, k" p6 e. O# l+ s, Q; L9 x
- 7 s+ e n0 @; c6 q! N$ N
- <dictionary name="21**大英汉词典">139305d43503a41a44ebf590fd8f3fae</dictionary>. U/ b: E6 k6 k: f, n
9 l$ d$ A. v+ W' K% B- >>> import hashlib
# f) g2 d% \/ _, l - >>> hashlib.md5('/home/henices/dictionary/21/21.mdd\0/home/henices/dictionary/21/21.mdx\0').hexdigest()% a/ A$ w9 H% p8 ^- ?8 i1 z8 S
- '139305d43503a41a44ebf590fd8f3fae'
$ ]* a$ i/ p$ \
复制代码 6 U8 b T; N1 w. z( x5 W1 j9 L
. q" q; R* G0 \使用的是 md5 哈希, 参见 dictionary.cc -> makeDictionaryId
7 ]1 z1 F" S4 M! Y& D) t; _' _4 W6 }% {6 y
6 T% M4 M) h% ^, m |; k$ I
% v3 {$ _( }+ B1 q: Y) n* u- string makeDictionaryId( vector< string > const & dictionaryFiles ) throw() 2 ]: r8 {8 e3 y# O+ `& V$ g' b
- {
7 E$ x( C- u) w# G3 q+ Y% H+ R - std::vector< string > sortedList; 7 [; W/ H3 [5 V, A
- * T, H! d( U$ G) o# D" m0 P0 P; R) `
- if ( Config::isPortableVersion() ) 5 I5 I. A7 @7 v1 T
- { + q+ g3 Y" C0 q8 L, j
- // For portable version, we use relative paths
2 P" x, ]' Q% @ - sortedList.reserve( dictionaryFiles.size() ); 9 j" A/ G- y' z z* B9 t
- $ ]; m* F# c2 n) u$ \: i: ]' D
- QDir dictionariesDir( Config::getPortableVersionDictionaryDir() ); - C' a# c. D( B- S$ P- ]
- - _+ Z7 @/ p# W( S2 q
- for( unsigned x = 0; x < dictionaryFiles.size(); ++x )
( g& |2 w O6 F0 W - {
% u5 V& F6 D; g% S8 M* t" P - string const & full( dictionaryFiles[ x ] ); ; e/ c. T& \) P7 i- V
- ' E' X0 ?* x' M1 `- g
- QFileInfo fileInfo( FsEncoding::decode( full.c_str() ) ); + I$ o6 e) b- J @, \# v+ Z
-
6 k3 N5 A5 d9 t3 C1 P9 U* t- a - if ( fileInfo.isAbsolute() )
. @! B, v% H. J - sortedList.push_back( FsEncoding::encode( dictionariesDir.relativeFilePath( fileInfo.filePath() ) ) );
- Z, O# W1 x. W - else # ]. H) O9 a% x( A) y- v
- {
7 E1 ~; P+ T; J! ~ - // Well, it's relative. We don't technically support those, but 3 q D( X6 b. L/ k( n" U; U
- // what the heck 8 }! K5 L0 ]" W9 ]3 X& e4 X
- sortedList.push_back( full ); # Z2 i8 X. C7 ]8 k% F# ?9 D
- } O) X1 J- _6 `9 ^4 T
- } 0 g7 |$ ?5 N# q7 |
- } # B& e' _7 D4 F" p `
- else
" a; \8 t/ N9 J4 \+ @& y1 I0 v - sortedList = dictionaryFiles; , e2 G4 g, D' w; m! x: C# k6 i
-
4 ?; V) u: \% b$ i3 ` - std::sort( sortedList.begin(), sortedList.end() );
6 E8 h( r3 E$ L! G3 s - * [' |( Y5 [6 [8 Y6 A# |: { n3 W1 h
- QCryptographicHash hash( QCryptographicHash::Md5 );
+ x4 H N7 {' B- M! ?5 ` `$ x - + Z: r# M4 K- X1 @$ ~* f0 W8 }; [
- for( std::vector< string >::const_iterator i = sortedList.begin();
! u* b4 l" }0 `9 L - i != sortedList.end(); ++i ) _0 G o% a0 \% w1 t
- hash.addData( i->c_str(), i->size() + 1 ); 4 K" Q- f# \$ t" k. P+ Y! X
-
% e% ]1 A! T( N# Q2 l6 c - return hash.result().toHex().data();
- z. z* P( r G+ f1 t9 J - } 6 E0 |' ` ~1 D, P U+ q
复制代码 8 ?7 w( l8 C3 r1 f3 `( P! g# z& D
& f+ w( l: V% b" E: A2 o
n! E- p/ ^ }3 S# y* J$ r" ^
各种来源的 ID 是随机生成的 (website/wiki/program/...) U* g0 @8 k# J8 A5 i
/ i6 u' Q+ B" C2 Z. H( i
sources.cc* Y/ |& i% W* [& F* o, Q3 J
/ G+ Z4 j: `2 T3 ^- d* G- void ProgramsModel::addNewProgram()
9 E+ o( H5 a8 `$ O/ ? \9 h# H - {
9 v+ f% ?5 m7 t3 y; z4 Y+ T3 I' c; ] - Config::Program p; ) L, M6 f, C1 A
- ( i- n0 U# J8 e" Z4 ]
- p.enabled = false;
5 a2 f0 l' S' I$ [0 W* a& |1 y - p.type = Config::Program::Audio; W6 O& L3 _, o5 `; w
- / @: q9 o0 I, a# }7 _
- p.id = Dictionary::generateRandomDictionaryId(); 0 c- k% A2 q* R, ]2 B6 S4 Y* M2 m' d
- W! o) m( q$ c) P$ `5 L! R r
- beginInsertRows( QModelIndex(), programs.size(), programs.size() ); 7 N+ E1 Y% e) q+ U
- programs.push_back( p );
% h! w s9 n! F - endInsertRows(); 6 l( `$ [, L8 H, H E: |4 J
- }
4 |; x6 c* e3 I7 x% {
复制代码
: W' I( v2 N/ i. t
y) C, `) Z3 ~3 q/ |- sdictionary.cc % F' O1 B" x, G4 t
- . R. N* O5 z; q3 B6 K: X
- QString generateRandomDictionaryId() , R* J. _: U. c% _/ J: T
- {
) o; {% I; S( \, C - return QString( ( m h: B& y' u4 F3 f
- QCryptographicHash::hash(
0 c* h& h% G0 G7 W - QDateTime::currentDateTime().toString( ""Random"dd.MM.yyyy hh:mm:ss.zzz" ).toUtf8(), ' ~6 z) r* V9 j0 V4 M9 c
- QCryptographicHash::Md5 ).toHex() );
4 E' t2 n7 Y0 P6 R; _& Z1 Z - }
# U$ [( m( }' M$ j( N
复制代码 5 d# K! ^ o4 V6 X3 [* v7 c1 S
|
评分
-
5
查看全部评分
-
|