|
本帖最后由 henices 于 2017-10-17 13:58 编辑
- P& Y: \ Z; G$ |
+ n- q/ e- i, Z, R6 P) \. thttp://www.pdawiki.com/forum/thread-21902-1-1.html [GoldenDict] 如何查看 GoldenDict 下某部词典的 ID ?- T# q# h" w* N" j; m; B1 @9 `& w
; t5 v) g8 Y9 B8 ?; @
+ E* Z+ K1 ^8 q' j* l$ ~9 s
- & f7 y8 n+ h' M! E
- <dictionary name="21**大英汉词典">139305d43503a41a44ebf590fd8f3fae</dictionary>3 N& E: `- v k
- 6 J5 x# R- b9 O; a7 \2 X
- >>> import hashlib / N3 o% B2 X t" d' \4 U. S
- >>> hashlib.md5('/home/henices/dictionary/21/21.mdd\0/home/henices/dictionary/21/21.mdx\0').hexdigest()
/ e4 L9 k) ?6 H1 G - '139305d43503a41a44ebf590fd8f3fae'
# l# v1 C) n% e% Z
复制代码
& n, F1 ]5 @+ l( v# M& |4 p C, [, F5 ~3 e( C6 |, U+ @0 i H
使用的是 md5 哈希, 参见 dictionary.cc -> makeDictionaryId& ]. L* e: U8 M
8 Y, z1 v5 H' @; p3 c
7 H6 W# c9 [; Q+ c8 @7 D0 p. E- string makeDictionaryId( vector< string > const & dictionaryFiles ) throw() " N0 x' i& W$ i' W) g
- { 0 B% x: J3 u# e) ^
- std::vector< string > sortedList; 5 ~( [( [: Q0 o3 k( i A, ?) M3 s
-
% H6 S0 X3 t {5 J* ^ - if ( Config::isPortableVersion() ) 0 P% {- ]# C4 C$ w. Y
- {
9 s0 l: l+ F7 J! S& e1 Q2 N& {# ^: u3 D - // For portable version, we use relative paths + K: r9 J9 x, ?7 [; _: h
- sortedList.reserve( dictionaryFiles.size() );
6 q' @. p4 U. O K0 t- a7 j3 w - ' m+ q# |$ ~. k; {5 S
- QDir dictionariesDir( Config::getPortableVersionDictionaryDir() ); 7 N |7 |3 j6 N# e( g$ e9 P, f
-
5 {% \7 Y4 a/ p) M+ J - for( unsigned x = 0; x < dictionaryFiles.size(); ++x ) ' X2 v! o& R4 ^' D
- { 5 [ L% w& Q$ Q5 `- l+ A x
- string const & full( dictionaryFiles[ x ] );
4 ~7 q! D7 A) _0 I0 @8 W -
+ s, m; h6 Z( Z2 `5 @ - QFileInfo fileInfo( FsEncoding::decode( full.c_str() ) );
; W- Q2 b* j: E: C$ J8 v5 ^+ q) a - $ E g q0 R; ]2 u
- if ( fileInfo.isAbsolute() )
0 A* Q/ A) F& H% \% w/ Z# I - sortedList.push_back( FsEncoding::encode( dictionariesDir.relativeFilePath( fileInfo.filePath() ) ) ); . u9 c& k4 T9 T* w$ ?
- else
. L. Q0 u7 K9 [" w3 J0 p1 q - { - F+ d# X4 P/ j1 n) K
- // Well, it's relative. We don't technically support those, but
* ?# H" h0 K2 U2 ]% e9 m/ G/ U$ ~ - // what the heck
* A* _- \# c" J& l0 t0 h - sortedList.push_back( full ); 0 J" ?2 Z6 j& G, A/ S
- } * ]9 p' K/ j: G5 V( O; ^
- }
0 V3 G6 U5 Z% G6 l& I2 ?$ n1 f" q; ]' _ - } ( j; f8 n4 T8 w. w3 o- h4 c
- else ! z$ U% v# X& h3 J
- sortedList = dictionaryFiles; , x3 O, V7 u( b& }4 W0 v
-
+ h5 H5 P3 u8 Z5 S' X: W" R S - std::sort( sortedList.begin(), sortedList.end() ); . M& A0 ^' Z) @/ g: J" g* J0 N
- 2 o3 e* C5 H4 N4 w5 D! h2 k" Q) M
- QCryptographicHash hash( QCryptographicHash::Md5 );
# U- n7 `* ?9 `( g - ! |- A; M" ]0 G/ M- o+ S/ l9 b
- for( std::vector< string >::const_iterator i = sortedList.begin();
7 @9 n% q9 p8 K) g4 u0 { - i != sortedList.end(); ++i ) , x/ c& p: v* x6 e
- hash.addData( i->c_str(), i->size() + 1 ); # ~9 ~2 R) M& f# O) ?
- . d$ n8 B+ v Q1 Y
- return hash.result().toHex().data(); 3 z3 d5 t* a$ o3 \9 J- C4 W! z P
- } 1 t% |4 y4 W; ]$ Q& D8 p
复制代码 : O! [; W6 L6 N" r; i1 ?9 j3 h0 g/ s
5 W' m) V6 [3 \0 f5 l+ H5 {% v6 o! Y* x, u h8 m" A/ S
各种来源的 ID 是随机生成的 (website/wiki/program/...)# ?: k9 z& X' T* a0 P% A- Q
8 s/ j) \3 X2 Z9 tsources.cc
# o" A- }2 {1 V2 H. n
: T4 {! _. K/ ]3 }3 b, _- void ProgramsModel::addNewProgram()
$ b/ {5 V& X8 v% e. G" A( d' w - {
+ E8 O& a2 y2 R% h/ Y5 Q - Config::Program p;
: P a- P3 v4 t1 M0 m7 G, H - # [% k. \% c) R& ~/ W
- p.enabled = false;
% _' ]3 X/ }7 l7 _ - p.type = Config::Program::Audio; + A, Z2 I$ p5 `9 a- g1 S% |
-
9 B' f$ M2 _# t. c5 l - p.id = Dictionary::generateRandomDictionaryId(); " Z& m' N" K: r; d. H
- 7 R3 D; P% J$ e2 x
- beginInsertRows( QModelIndex(), programs.size(), programs.size() );
; l& D9 _$ d+ I% [ - programs.push_back( p ); ' ]+ O( Y n9 ^- F" u
- endInsertRows();
! [, j9 Y. V" U K - } - X0 n. N) x( O% w
复制代码
, M0 e G! ?9 }" X% y& l$ J ^# N9 a+ W0 S# x0 x' o6 h
dictionary.cc L9 }3 j7 Z# ^, Z# T
1 g. _% T8 v, m3 g& v" h- QString generateRandomDictionaryId() ; O& |/ t! w" ]: u( O
- {
/ A) Y0 h" l+ v3 ? - return QString( 0 @" I' [6 l! m7 j
- QCryptographicHash::hash( # J, u6 d, O$ f3 Y0 \# z
- QDateTime::currentDateTime().toString( ""Random"dd.MM.yyyy hh:mm:ss.zzz" ).toUtf8(),
9 S7 F0 ?7 A! R1 `& V2 ^3 k4 z6 _4 U - QCryptographicHash::Md5 ).toHex() ); : X' g7 A& d+ Y
- } 4 w0 t O) I0 E. O" a5 P/ Y5 ?
复制代码
! W( X8 f% y$ _) A; K* p |
评分
-
5
查看全部评分
-
|