--- XanBG1Friend/setup-xanbg1friend.tp2	Thu May 15 11:23:16 2014
+++ XanBG1Friend/setup-xanbg1friend.tp2	Thu Feb 11 13:09:02 2016
@@ -1,56 +1,37 @@
 // Setup
 BACKUP ~XanBG1Friend/Backup~
 AUTHOR ~Kulyok http://forums.pocketplane.net~
-VERSION ~v9bgee~ /* Thanks to Isaya for changes for v9 for BGEE; Kaeloree did the rest, BGEE-wise */
+VERSION ~v9bgee BWP Fix 4~ /* Thanks to Isaya for changes for v9 for BGEE; Kaeloree did the rest, BGEE-wise */
 README ~XanBG1Friend/Readme-XanBG1Friend.txt~
 
 
 // BG:EE TRA compatibility
 ALWAYS
-ACTION_IF GAME_IS ~bgee~ THEN BEGIN
-  /* It's safe to convert for any language and for all operating systems, no test required */
-
+  ACTION_IF "%WEIDU_OS%" STRING_EQUAL_CASE ~win32~ BEGIN
+    AT_NOW ~if not exist "iconv" mkdir iconv~
+    AT_NOW ~if not exist "iconv\iconv.exe" copy "BiG World Fixpack\_utils\iconv" "iconv"~
+  END
   /* BG:EE tra conversion : Character encoding for BG II for various languages: ensure the name matches the menu choices */
-  ACTION_DEFINE_ASSOCIATIVE_ARRAY languageencoding BEGIN
-    "English" => "CP1252"
-    "Russian" => "CP1251"
-    "German" => "CP1252"
-    "French" => "CP1252"
-    "Italian" => "CP1252"
+  ACTION_DEFINE_ASSOCIATIVE_ARRAY tra#charsets BEGIN
+    "english" => "CP1252"
+    "russian" => "CP1251"
+    "german" => "CP1252"
+    "french" => "CP1252"
+    "italian" => "CP1252"
   END
-  OUTER_SPRINT initialencoding ~~
-  ACTION_PHP_EACH languageencoding AS lang => encoding BEGIN
-    ACTION_IF ("%LANGUAGE%" STRING_EQUAL_CASE ~%lang%~ = 1) THEN BEGIN
-      OUTER_SPRINT initialencoding ~%encoding%~
-    END
+  ACTION_DEFINE_ARRAY tra#reload BEGIN O#XanBG1 END
+  LAF HANDLE_CHARSETS
+    STR_VAR
+      charset_table = tra#charsets
+      tra_path      = EVAL ~%MOD_FOLDER%~
+      iconv_path    = ~iconv~
+      reload_array  = tra#reload
   END
-
-  /* Since there is only one component, we don't need a marker file to avoid repeating conversion for each component */
-  ACTION_IF (STRING_LENGTH ~%initialencoding%~ != 0) THEN BEGIN
-    ACTION_IF ("%WEIDU_OS%" STRING_EQUAL_CASE ~WIN32~ = 1) THEN BEGIN
-      /* Only convert for the language selected by passing the directory as parameter */
-      PRINT ~Windows conversion with %initialencoding%~
-      AT_NOW ~xanbg1friend/conv_tra.bat %LANGUAGE% %initialencoding%~
-    END
-    ACTION_IF ("%WEIDU_OS%" STRING_EQUAL_CASE ~OSX~ = 1) OR ("%WEIDU_OS%" STRING_EQUAL_CASE ~UNIX~ = 1) THEN BEGIN
-      /* Only convert for the language selected by passing the directory as parameter */
-      PRINT ~Linux and Mac conversion with %initialencoding%~
-      AT_NOW ~xanbg1friend/conv_tra.sh %LANGUAGE% %initialencoding%~
-    END
-
-    /* The tra files has to be replaced with its counterpart from the utf8 directory, then loaded */
-    /* Otherwise the tra file for dialogs is still with the Windows 1252 / 1251 encoding */
-    MOVE ~xanbg1friend/%LANGUAGE%/utf8/o#xanbg1.tra~ ~xanbg1friend/%LANGUAGE%/o#xanbg1.tra~
-    LOAD_TRA ~xanbg1friend/%LANGUAGE%/o#xanbg1.tra~
-    PRINT ~re-loaded %LANGUAGE% TRA files~
-  END
-END
 END
-
 
 // Languages
 AUTO_TRA ~XanBG1Friend/%s~
 LANGUAGE ~English~ ~English~ ~XanBG1Friend/English/O#XanBG1.tra~
 LANGUAGE ~Russian~ ~Russian~ ~XanBG1Friend/Russian/O#XanBG1.tra~
 LANGUAGE ~German (Translated by Steffen)~ ~German~ ~XanBG1Friend/German/O#XanBG1.tra~
 LANGUAGE ~French (Translated by Eleima)~ ~French~ ~XanBG1Friend/French/O#XanBG1.tra~
