4 # Praat script handling configuration page
6 # SpeakGoodChinese: Config.praat loads the code needed for the
7 # settings and the Settings page of SpeakGoodChinese.
9 # Copyright (C) 2007-2010 R.J.J.H. van Son and 2010 the Netherlands Cancer Institute
10 # The SpeakGoodChinese team are:
11 # Guangqin Chen, Zhonyan Chen, Stefan de Koning, Eveline van Hagen,
12 # Rob van Son, Dennis Vierkant, David Weenink
14 # This program is free software; you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
29 ###############################################################
31 # Button Drawing Routines
33 ###############################################################
35 procedure DrawCredits .color$ .x .y .size
38 call adjustFontSizeOnHeight 'defaultFont$' 24 '.lineheight'
39 .currentFontSize = adjustFontSizeOnHeight.newFontSize
40 demo Paint circle... {0.2,0.2,0.8} '.x' '.y' '.size'
42 demo Text special... '.x' centre '.y' half Times '.currentFontSize' 0 i
45 call set_font_size 'defaultFontSize'
48 procedure DrawDeleteList .color$ .x .y .size
56 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
59 .maxWidth = (.rightX - .leftX)
60 .currentFontSize = defaultFontSize
61 call adjustFontSizeOnWidth 'defaultFont$' '.currentFontSize' '.maxWidth' '.displayWordList$'
62 .currentFontSize = adjustFontSizeOnWidth.newFontSize
63 if adjustFontSizeOnWidth.diff > 0
64 .rightX += adjustFontSizeOnWidth.diff/2
65 .leftX -= adjustFontSizeOnWidth.diff/2
67 call set_font_size '.currentFontSize'
68 demo Paint rectangle... White '.leftX' '.rightX' '.botY' '.topY'
70 demo Text... '.x' Centre '.botY' Bottom '.displayWordList$'
73 call set_font_size 'defaultFontSize'
76 procedure DrawLogging .color$ .x .y .size
80 .color$ = "{0.5,0.5,1}"
84 demo Paint circle... '.color$' '.x' '.y' '.size'
87 ###############################################################
89 # Obligatory button Drawing Routines
91 # These MUST be defined
93 ###############################################################
95 procedure DrawReturn .color$ .x .y .size
96 call DrawConfig '.color$' '.x' '.y' '.size'
99 # Set the correct button states after redrawing the window
100 procedure setConfigMainPage
101 # Handle logging buttons with forced button draw
102 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
103 call Draw_button 'config$' +!Logging 'config.logPerformance'
107 ###############################################################
109 # Button Processing Routines
111 ###############################################################
113 procedure processConfigShuffleLists .clickX .clickY .pressed$
115 .label$ = "ShuffleLists"
116 config.shuffleLists = not config.shuffleLists
117 .displayButton = 2*config.shuffleLists
118 call Draw_button '.table$' '.label$' '.displayButton'
121 procedure processConfigUseSoundExample .clickX .clickY .pressed$
123 .label$ = "UseSoundExample"
124 config.useSoundExample = not config.useSoundExample
125 .displayButton = 2*config.useSoundExample
126 call Draw_button '.table$' '.label$' '.displayButton'
129 procedure processConfigSynthesis .tts$ .clickX .clickY .pressed$
131 .label$ = "Synthesis_'.tts$'"
132 if speakCommandFile$ <> "" and fileReadable(speakCommandFile$)
133 if config.synthesis$ = ""
134 config.synthesis$ = .tts$
137 config.synthesis$ = ""
141 config.synthesis$ = "_DISABLED_"
144 call Draw_button '.table$' '.label$' '.displayButton'
147 procedure processConfigStrict .clickX .clickY .pressed$
150 config.strict = not config.strict
156 call Draw_button '.table$' '.label$' '.displayButton'
159 procedure processConfigDisplayPinyin .clickX .clickY .pressed$
161 .label$ = "DisplayPinyin"
162 config.displayPinyin = not config.displayPinyin
163 .displayButton = 2*config.displayPinyin
164 call Draw_button '.table$' '.label$' '.displayButton'
167 procedure processConfigDisplayChar .clickX .clickY .pressed$
169 .label$ = "DisplayChar"
170 config.displayChar = not config.displayChar
171 .displayButton = 2*config.displayChar
172 call Draw_button 'table$' '.label$' '.displayButton'
175 procedure processConfigDisplayTrans .clickX .clickY .pressed$
177 .label$ = "DisplayTrans"
178 config.displayTrans = not config.displayTrans
179 .displayButton = 2*config.displayTrans
180 call Draw_button 'table$' '.label$' '.displayButton'
183 procedure processConfigDisplayNumbers .clickX .clickY .pressed$
185 .label$ = "DisplayNumbers"
186 config.displayNumbers = not config.displayNumbers
187 .displayButton = 2*config.displayNumbers
188 call Draw_button 'table$' '.label$' '.displayButton'
191 procedure processConfigLanguage .language$ .clickX .clickY .pressed$
193 .label$ = "Language_'.language$'"
194 call processLanguageCodes '.table$' '.label$'
197 procedure processConfigShowBackground .clickX .clickY .pressed$
199 .label$ = "ShowBackground"
200 config.showBackground = not config.showBackground
201 .displayButton = 2*config.showBackground
202 call Draw_button 'table$' '.label$' '.displayButton'
205 procedure processConfigInput .input$ .clickX .clickY .pressed$
207 .label$ = "Input_'.input$'"
208 call Draw_button '.table$' Input_'config.input$' 0
209 config.input$ = .input$
210 call Draw_button '.table$' Input_'config.input$' 2
213 procedure processConfigRegister .register .clickX .clickY .pressed$
215 .label$ = "Register_'.register'"
216 call setRegisterFromLabel '.table$' '.label$'
219 procedure setRegisterFromLabel .table$ .label$
220 call Draw_button '.table$' Register_'config.register' 0
221 call Draw_button '.table$' '.label$' 2
222 # Someone might have to use more than 3 chars for the config.register code
223 .numChars = length(.label$) - length("Register_")
224 .registerText$ = right$(.label$, .numChars)
225 config.register = '.registerText$'
228 procedure processConfigDeleteWordlist .clickX .clickY .pressed$
230 .label$ = "DeleteWordlist"
232 # Do not process undeletable word lists, only those stored in the
233 # preferencesDirectory$ can be deleted
234 if fileReadable("'sgc2wordlists$'/'wordlistName$'")
235 call findLabel '.table$' !'.label$'
237 select Table '.table$'
238 .alertText$ = Get value... 'findLabel.row' Text
239 .confirmKey$ = Get value... 'findLabel.row' Key
240 .popupText$ = Get value... 'findLabel.row' Helptext
242 exit Cannot find delete directive: '.table$' !'.label$'
244 call write_text_popup 'defaultFont$' 14 '.popupText$'
245 call Draw_button '.table$' '.label$' 2
246 alertText$ = .alertText$
247 call Draw_button '.table$' '.label$' 3
250 # Wait for confirmation
252 if demoInput(.confirmKey$)
253 .deleteWordListDir$ = wordlistName$
254 call load_word_list "'localWordlistDir$'" 1
255 call removeWordlist '.deleteWordListDir$'
257 call Draw_button '.table$' '.label$' 0
258 call Draw_config_page
262 wordlistTag$ = "Wordlist name"
263 procedure processConfigInstallWordlist .clickX .clickY .pressed$
265 .label$ = "InstallWordlist"
266 call Draw_button '.table$' '.label$' 1
268 # Do not use the automatic sgc list option, ask for a wordlist NAME
270 call findLabel '.table$' '.label$'
272 select Table '.table$'
273 .openDialogue$ = Get value... '.row' Helptext
274 call convert_praat_to_utf8 '.openDialogue$'
275 .openDialogue$ = convert_praat_to_utf8.text$
276 .wordlistButton$ = replace$(wordlistTag$, " ", "_", 0)
277 .wordlistButton$ = replace_regex$(.wordlistButton$, "^.", "\l&", 0)
278 beginPause(.openDialogue$)
279 sentence (wordlistTag$, "")
280 clicked = endPause ("Cancel", "Open", 2)
283 .wordlist_Name$ = '.wordlistButton$'$
285 call install_wordlists_by_name '.wordlist_Name$'
287 call sgc2wordlist 'homeDirectory$'
288 call sgc2wordlist 'homeDirectory$'/Downloads
289 call sgc2wordlist 'homeDirectory$'/Documents
290 call sgc2wordlist 'homeDirectory$'/My Documents
291 call sgc2wordlist 'homeDirectory$'/My Documents/Downloads
292 call sgc2wordlist 'homeDirectory$'/Desktop
293 call sgc2wordlist 'preferencesAppDir$'
295 call load_word_list "'localWordlistDir$'" 0
296 call Draw_button '.table$' '.label$' 0
297 call Draw_config_page
300 procedure processConfigOpenWordlist .clickX .clickY .pressed$
302 .label$ = "OpenWordlist"
303 call Draw_button '.table$' '.label$' 1
306 call findLabel '.table$' '.label$'
308 select Table '.table$'
309 .openDialogue$ = Get value... '.row' Helptext
310 call convert_praat_to_utf8 '.openDialogue$'
311 .openDialogue$ = convert_praat_to_utf8.text$
313 .wordlist_Name$ = chooseReadFile$ (.openDialogue$)
314 call install_wordlists_by_name '.wordlist_Name$'
315 call load_word_list "'localWordlistDir$'" 0
316 call Draw_button '.table$' '.label$' 0
317 call Draw_config_page
320 procedure processConfigPerformance .clickX .clickY .pressed$
322 .label$ = "Performance"
323 call Draw_button '.table$' '.label$' 1
324 call displaySummaryToneEvaluation
325 call Draw_button '.table$' '.label$' 0
326 call Draw_config_page
329 procedure processConfigSavePerf .clickX .clickY .pressed$
332 call Draw_button '.table$' '.label$' 1
335 call findLabel '.table$' '.label$'
337 select Table '.table$'
338 .openDialogue$ = Get value... '.row' Helptext
339 call convert_praat_to_utf8 '.openDialogue$'
340 .openDialogue$ = convert_praat_to_utf8.text$
342 .wordlist_Name$ = chooseWriteFile$ (.openDialogue$, "Performance.Table")
343 if .wordlist_Name$ <> ""
344 select Table 'initialiseSGC2.toneevaluation_table$'
345 Write to table file... '.wordlist_Name$'
348 call Draw_button '.table$' '.label$' 0
349 call Draw_config_page
352 ###############################################################
354 # Obligatory button Processing Routines
356 # These MUST be defined
358 ###############################################################
360 procedure processConfigReturn .clickX .clickY .pressed$
363 call Draw_button '.table$' '.label$' 1
364 call write_preferences ""
367 procedure processConfigRefresh .clickX .clickY .pressed$
370 call Draw_config_page
373 procedure processConfigCredits .clickX .clickY .pressed$
376 call Draw_button '.table$' '.label$' 1
377 call write_text_table Credits_'config.language$'
379 call Draw_button '.table$' '.label$' 0
381 call Draw_config_page
384 procedure processConfigHelp .clickX .clickY .pressed$
387 call help_loop '.table$' Draw_config_page
390 ###############################################################
392 # Miscelaneous supporting code
394 ###############################################################
395 procedure install_wordlists_by_name .wordlist_Name$
396 if .wordlist_Name$ <> ""
397 printline '.wordlist_Name$'
398 if index(.wordlist_Name$, "/")
399 .sourceDir$ = left$(.wordlist_Name$, rindex(.wordlist_Name$, "/") -1)
400 .file$ = right$(.wordlist_Name$, length(.wordlist_Name$) - rindex(.wordlist_Name$, "/"))
401 call readWordlist "'.sourceDir$'" '.file$'
404 if index(.wordlist_Name$, ".")
407 .extension1$ = ".sgc"
408 .extension2$ = ".Table"
409 .extension3$ = ".txt"
411 for .e from .start to 4
412 .currentExtension$ = .extension'.e'$
413 call readWordlist "'homeDirectory$'" '.wordlist_Name$''.currentExtension$'
414 call readWordlist "'homeDirectory$'/Downloads" '.wordlist_Name$''.currentExtension$'
415 call readWordlist "'homeDirectory$'/Documents" '.wordlist_Name$''.currentExtension$'
416 call readWordlist "'homeDirectory$'/My Documents/Downloads" '.wordlist_Name$''.currentExtension$'
417 call readWordlist "'homeDirectory$'/My Documents" '.wordlist_Name$''.currentExtension$'
418 call readWordlist "'homeDirectory$'/Desktop" '.wordlist_Name$''.currentExtension$'
419 call readWordlist "'preferencesAppDir$'" '.wordlist_Name$''.currentExtension$'
425 # Word lists: It is a VERY good idea to make sure that word-lists
427 procedure load_word_list .localdir$ .relnumber
428 # Remove old word list
430 select Table 'wordlist$'
432 call wipeArea 'wipeWordlistArea$'
436 # Create Table that will recieve the wordlists and directories
437 Create Table with column names... AllWordLists 0 Name Directory
438 .currentWordlistRow = 0
440 # Start with the word lists in the distribution, unless the local directory exists!
441 if not fileReadable(.localdir$)
442 call CreateCreateWordlists
443 select Table CreateWordlists
444 .numLists = Get number of rows
446 select Table CreateWordlists
447 .currentName$ = Get value... '.i' Name
448 .currentDirectory$ = "*call Create'.currentName$'"
449 select Table AllWordLists
451 .currentWordlistRow = Get number of rows
452 Set string value... '.currentWordlistRow' Name '.currentName$'
453 .currentDirectory$ = "*call Create'.currentName$'"
454 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
456 select Table CreateWordlists
460 # First the global word lists
461 if fileReadable(globalwordlists$)
462 Create Strings as directory list... WordList 'globalwordlists$'
463 .numLists = Get number of strings
465 select Strings WordList
466 .currentName$ = Get string... '.i'
467 select Table AllWordLists
469 .currentWordlistRow = Get number of rows
470 Set string value... '.currentWordlistRow' Name '.currentName$'
471 .currentDirectory$ = globalwordlists$+"/"+.currentName$
472 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
474 select Strings WordList
478 # Now the preferences word lists
479 if fileReadable(sgc2wordlists$)
480 Create Strings as directory list... WordList 'sgc2wordlists$'
481 .numLists = Get number of strings
483 select Strings WordList
484 .currentName$ = Get string... '.i'
485 select Table AllWordLists
487 .currentWordlistRow = Get number of rows
488 Set string value... '.currentWordlistRow' Name '.currentName$'
489 .currentDirectory$ = sgc2wordlists$+"/"+.currentName$
490 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
492 select Strings WordList
496 # Finally, the local word lists
497 if fileReadable(.localdir$)
498 Create Strings as directory list... WordList '.localdir$'
499 .numLists = Get number of strings
501 select Strings WordList
502 .currentName$ = Get string... '.i'
503 select Table AllWordLists
505 .currentWordlistRow = Get number of rows
506 Set string value... '.currentWordlistRow' Name '.currentName$'
507 .currentDirectory$ = .localdir$+"/"+.currentName$
508 Set string value... '.currentWordlistRow' Directory '.currentDirectory$'
510 select Strings WordList
514 # Get the position of the current word list
515 select Table AllWordLists
517 .numLists = Get number of rows
518 if wordlistName$ <> ""
519 select Table AllWordLists
520 .currentNumber = Search column... Name 'wordlistName$'
522 wordlistNum = .currentNumber + .relnumber
523 if wordlistNum > .numLists
525 elsif wordlistNum < 1
526 wordlistNum = .numLists
528 select Table AllWordLists
529 wordlistName$ = Get value... 'wordlistNum' Name
530 .dirWordlistName$ = Get value... 'wordlistNum' Directory
531 .dirString$ = replace_regex$(.dirWordlistName$, "[ ]", "&", 0)
533 # Read in full tables
534 if fileReadable("'.dirString$'/wordlist.Table")
535 Read from file... '.dirString$'/wordlist.Table
536 Rename... 'wordlistName$'
537 # Praat wil change the name if it feels like it
538 wordlist$ = selected$("Table")
539 # Handle (legacy) simple word lists
540 elsif fileReadable("'.dirString$'/wordlist.txt")
541 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
542 wordlist$ = selected$("Table")
543 Read Strings from raw text file... '.dirString$'/wordlist.txt
544 Rename... RawWordList
545 .numWordStrings = Get number of strings
546 for .i to .numWordStrings
547 select Strings RawWordList
548 .currentLine$ = Get string... '.i'
549 .currentPinyin$ = extractWord$(.currentLine$, "")
550 if length(.currentLine$) > length(.currentPinyin$)+1
551 .currentFile$ = right$(.currentLine$, length(.currentPinyin$)+1)
552 elsif fileReadable("'.dirString$'/'.currentPinyin$'.spx")
553 .currentFile$ = .currentPinyin$+".spx"
554 elsif fileReadable("'.dirString$'/'.currentPinyin$'.flac")
555 .currentFile$ = .currentPinyin$+".flac"
556 elsif fileReadable("'.dirString$'/'.currentPinyin$'.wav")
557 .currentFile$ = .currentPinyin$+".wav"
558 elsif fileReadable("'.dirString$'/'.currentPinyin$'.mp3")
559 .currentFile$ = .currentPinyin$+".mp3"
563 select Table 'wordlist$'
565 Set string value... '.i' Pinyin '.currentPinyin$'
566 Set string value... '.i' Sound '.currentFile$'
568 select Strings RawWordList
571 select Table 'wordlist$'
572 elsif fileReadable(.dirString$)
573 Create Table with column names... "'wordlistName$'" 0 Pinyin Sound
574 wordlist$ = selected$("Table")
575 Create Strings as file list... RawWordList '.dirString$'/*
576 .numWordStrings = Get number of strings
578 for .j to .numWordStrings
579 select Strings RawWordList
580 .currentLine$ = Get string... '.j'
581 .currentFile$ = extractWord$(.currentLine$, "")
582 if index_regex(.currentFile$, "\.(spx|flac|wav|mp3)")
583 .currentPinyin$ = left$(.currentFile$, index(.currentFile$, ".")-1)
584 select Table 'wordlist$'
587 Set string value... '.i' Pinyin '.currentPinyin$'
588 Set string value... '.i' Sound '.currentFile$'
591 select Strings RawWordList
594 select Table 'wordlist$'
595 elsif startsWith(.dirString$, "*call ")
596 .callProcedure$ = right$(.dirString$, length(.dirString$)-1)
598 wordlist$ = selected$("Table")
601 # Can this wordlist be deleted?
602 if fileReadable("'sgc2wordlists$'/'wordlistName$'")
603 config.deleteWordlist = 0
605 config.deleteWordlist = -1
608 # Add a Character and Translation column if missing
609 select Table 'wordlist$'
610 numberOfWords = Get number of rows
611 .characterColumn = Get column index... Character
612 if not .characterColumn
613 Append column... Character
614 for .i to numberOfWords
615 Set string value... '.i' Character -
618 .translationColumn = Get column index... Translation
619 if not .translationColumn
620 Append column... Translation
621 for .i to numberOfWords
622 Set string value... '.i' Translation -
626 # Remove all rows without Pinyin
627 .numRows = Get number of rows
629 .rowNum = .numRows - i + 1
630 .pinyinValue$ = Get value... '.rowNum' Pinyin
631 if not index_regex(.pinyinValue$, "[a-zA-Z0-9]")
632 Remove row... '.rowNum'
635 numberOfWords = Get number of rows
637 # Shuffle words if requested
638 if config.shuffleLists
643 select Table AllWordLists
646 # There were no Word Lists
649 wordlistName$ = "No Word Lists available"
651 Create Table with column names... "'wordlistName$'" 0 Pinyin Character Translation Sound
652 wordlist$ = selected$("Table")
656 Set string value... '.i' Pinyin ni3hao3
657 Set string value... '.i' Character -
658 Set string value... '.i' Translation -
659 Set string value... '.i' Sound -
662 Set string value... '.i' Pinyin xie4xie0
663 Set string value... '.i' Character -
664 Set string value... '.i' Translation -
665 Set string value... '.i' Sound -
668 Set string value... '.i' Pinyin zai4jian4
669 Set string value... '.i' Character -
670 Set string value... '.i' Translation -
671 Set string value... '.i' Sound -
672 numberOfWords = Get number of rows
675 call set_window_title 'buttons$' 'wordlistName$'
678 procedure display_word_list_name
682 .displayWordList$ = replace_regex$(wordlistName$, "[_]", " ", 0)
683 call wipeArea 'wipeWordlistArea$'
684 call adjustFontSizeOnHeight 'defaultFont$' 'defaultFontSize' 5
685 .currentFontSize = adjustFontSizeOnHeight.newFontSize
688 demo Text special... '.xtext' Centre '.ytext' Bottom Helvetica '.currentFontSize' 0 '.displayWordList$'
691 call set_font_size 'defaultFontSize'
694 procedure write_word_list
696 call draw_tone_contour
698 # Write current Pinyin text
699 call display_text Black
701 # Write the current word list name
702 call display_word_list_name
705 procedure start_logging
706 if fileReadable("'preferencesLogDir$'/logPerformance.txt")
707 .logDirectory$ < 'preferencesLogDir$'/logPerformance.txt
708 .logDirectory$ = extractWord$(.logDirectory$, "")
709 if .logDirectory$ = "" or not fileReadable(.logDirectory$)
710 .logDirectory$ = "'preferencesLogDir$'"
712 createDirectory("'.logDirectory$'/sgc2log")
713 currentLogDirectory$ = "'.logDirectory$'/sgc2log/log'logtimeStamp$'"
714 createDirectory(currentLogDirectory$)
715 if not fileReadable("'currentLogDirectory$'/wordlist.Table")
716 .headerLine$ = "Pinyin'tab$'Character'tab$'Sound'newline$'"
717 .headerLine$ > 'currentLogDirectory$'/wordlist.Table
720 config.logPerformance = 1
724 procedure log_performance .recordedSound$ .register .proficiency .pinyin$ .choice$
726 .currentDate$ = date$()
727 .timeStamp$ = replace_regex$(.currentDate$, "[^a-zA-Z0-9\-_]", "-", 0)
728 .choiceText$ = replace_regex$(.choice$, "[^a-zA-Z0-9\-_]", "-", 0)
730 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
731 .outfilename$ = .pinyin$+"_"+.choice$+"_'.register'_"+.timeStamp$+".wav"
732 .logtext$ = .pinyin$+tab$+.choice$+tab$+"'.register'Hz"+tab$+.currentDate$+tab$+.outfilename$+newline$
734 fileappend 'currentLogDirectory$'/logFile.txt '.logtext$'
736 fileappend 'currentLogDirectory$'/wordlist.Table '.pinyin$''tab$''.choice$''tab$''.outfilename$''newline$'
738 select Sound 'recordedSound$'
739 Write to WAV file... 'currentLogDirectory$'/'.outfilename$'
743 procedure paint_logging_light
745 .row = Search column... Label !Logging
747 exit Button Table Config does not have a row with label !Logging
750 .leftX = Get value... '.row' LeftX
751 .rightX = Get value... '.row' RightX
752 .lowY = Get value... '.row' LowY
753 .highY = Get value... '.row' HighY
754 .buttonColor$ = Get value... '.row' Color
755 .centerX = (.leftX + .rightX)/2
756 .centerY = (.lowY + .highY)/2
757 .radius = (.highY - .lowY )/(4*2)
758 .wipeRadius = 1.1*.radius
759 if config.logPerformance and fileReadable("'preferencesLogDir$'/logPerformance.txt")
760 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
761 demo Paint circle... '.buttonColor$' '.centerX' '.centerY' '.radius'
764 demo Paint circle... White '.centerX' '.centerY' '.wipeRadius'
769 # Uninstall word lists
770 procedure removeWordlist .deletedWordlistName$
772 if fileReadable("'sgc2wordlists$'/'.deletedWordlistName$'")
773 .targetDir$ = "'sgc2wordlists$'/'.deletedWordlistName$'"
775 Create Strings as file list... DeleteList '.targetDir$'/*
776 .numdeleteFiles = Get number of strings
777 for .i to .numdeleteFiles
778 .file$ = Get string... '.i'
779 deleteFile("'.targetDir$'/'.file$'")
781 deleteFile("'.targetDir$'")
782 select Strings DeleteList
787 procedure sgc2wordlist .sourceDir$
788 if startsWith(.sourceDir$, "preferencesDirectory$")
789 .sourceDir$ = replace$(.sourceDir$, "preferencesDirectory$", preferencesDirectory$)
792 .targetDirectory$ = "'sgc2wordlists$'"
793 if fileReadable(.sourceDir$)
794 Create Strings as file list... PackageList '.sourceDir$'/*.sgc
795 .numFiles = Get number of strings
797 select Strings PackageList
798 .file$ = Get string... '.i'
799 call readWordlist '.sourceDir$' '.file$'
802 select Strings PackageList
807 # Debuggin remarks!!!
808 # fileReadable(<directory>) werkt niet in Windows
809 # De file paths / -> \\ must be performed on the filenames in Windows before the system_nocheck is given
810 # And yet only the 7z decompression has been implemented
811 windowsUnzipCommand$ = """C:\Program Files\7-Zip\7z"" x"
812 procedure readWordlist .sourceDir$ .file$
813 # No use doing anything if the source does not exist
814 if fileReadable("'.sourceDir$'/'.file$'")
815 # What will be the target wordlist directory?
816 .targetDirectory$ = "'sgc2wordlists$'"
817 .dirname$ = left$(.file$, rindex(.file$, ".")-1)
821 .wordlistDirectory$ = .targetDirectory$+"/"+.dirname$
822 # Wordlist directory does not exist, neither locally nor in the preferences
823 if not (fileReadable(.dirname$) or fileReadable(.wordlistDirectory$))
825 # Move source to destination
826 if index(.file$, ".sgc")
827 # Create wordlist directory
828 createDirectory(.wordlistDirectory$)
831 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/"'
832 system cd ''.wordlistDirectory$'';bash -rc -- 'unzip "'.file$'"'
834 system copy "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/"
835 system chdir "'.wordlistDirectory$'" && 'windowsUnzipCommand$' "'.file$'"
837 deleteFile("'.wordlistDirectory$'/'.file$'")
838 elsif index_regex(.file$, "\.(Table|txt)")
839 # Create wordlist directory
840 createDirectory(.wordlistDirectory$)
842 .extension$ = replace_regex$(.file$, "^.+\.(Table|txt)$", "\1", 0)
844 system bash -rc -- 'cp "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/wordlist.'.extension$'"'
846 system copy "'.sourceDir$'/'.file$'" "'.wordlistDirectory$'/wordlist.'.extension$'"
848 elsif fileReadable("'.sourceDir$'/'.file$'/wordlist.Table") or fileReadable("'.sourceDir$'/'.file$'/wordlist.txt")
849 # Create wordlist directory
850 createDirectory(.wordlistDirectory$)
852 .sourceFiles = Create Strings as file list... SourceStrings '.sourceDir$'/'.file$'/
853 .numFiles = Get number of strings
855 select '.sourceFiles'
856 .currentFile$ = Get string... '.i'
858 system bash -rc -- 'cp "'.sourceDir$'/'.file$'/'.currentFile$'" "'.wordlistDirectory$'/"'
860 system copy "'.sourceDir$'/'.file$'/'.currentFile$'" "'.wordlistDirectory$'/"
863 select '.sourceFiles'
867 # Set current word list to read list
869 wordlistName$ = .dirname$
872 .label$ = "!NotAWordlist"
875 call findLabel '.table$' '.label$'
877 select Table '.table$'
878 .helpText$ = Get value... '.row' Helptext
879 .filetext$ = replace_regex$("'.sourceDir$'/'.file$'", "_", "\\_ ", 0)
880 call write_text_popup 'defaultFont$' 14 '.helpText$' "'.filetext$'"
881 # Wait for confirmation