unix.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "global.h"
  5. #include "util.h"
  6. #include "palcfg.h"
  7. #include <syslog.h>
  8. #ifndef PAL_NO_LAUNCH_UI
  9. #include <FL/Fl.H>
  10. #include <FL/Fl_Window.H>
  11. #include <FL/Fl_Box.H>
  12. #include <FL/Fl_Button.H>
  13. #include <FL/Fl_Check_Button.H>
  14. #include <FL/Fl_Radio_Round_Button.H>
  15. #include <FL/Fl_Hor_Value_Slider.H>
  16. #include <FL/Fl_Input.H>
  17. #include <FL/Fl_Int_Input.H>
  18. #include <FL/Fl_Choice.H>
  19. struct {
  20. Fl_Input* gamepath;
  21. Fl_Input* fontfile;
  22. Fl_Input* logfile;
  23. Fl_Input* msgfile;
  24. Fl_Check_Button* touch;
  25. Fl_Check_Button* aspect;
  26. Fl_Check_Button* fullscreen;
  27. Fl_Check_Button* avi;
  28. Fl_Choice* loglevel;
  29. Fl_Choice* cd;
  30. Fl_Choice* bgm;
  31. Fl_Choice* opl;
  32. Fl_Int_Input* samplerate;
  33. Fl_Check_Button* stereo;
  34. Fl_Int_Input* oplrate;
  35. Fl_Check_Button* surround;
  36. Fl_Int_Input* buffer;
  37. Fl_Hor_Value_Slider* quality;
  38. Fl_Hor_Value_Slider* music;
  39. Fl_Hor_Value_Slider* sound;
  40. } gWidgets;
  41. struct {
  42. const char* title;
  43. const char* language;
  44. const char* display;
  45. const char* audio;
  46. const char* logging;
  47. const char* gamepath;
  48. const char* msgfile;
  49. const char* fontfile;
  50. const char* logfile;
  51. const char* loglevel;
  52. const char* touch;
  53. const char* aspect;
  54. const char* fullscreen;
  55. const char* avi;
  56. const char* cd;
  57. const char* bgm;
  58. const char* opl;
  59. const char* samplerate;
  60. const char* stereo;
  61. const char* oplrate;
  62. const char* surround;
  63. const char* musvol;
  64. const char* sndvol;
  65. const char* buffer;
  66. const char* quality;
  67. const char* exit;
  68. const char* launch;
  69. const char* def;
  70. const char* levels;
  71. } gLabels[3] = {
  72. { "SDLPAL Launcher", "Language & Font", "Display", "Audio", "Logging",
  73. "Game resource path:", "Message file:", "Font file:", "Log file:", "Log level:",
  74. "Use touc&h overlay", "&Keep aspect ratio", "&Full screen", "Enable A&VI","&CD type:",
  75. "&BGM type:", "&OPL type:", "Sample rate:", "Ste&reo", "OPL rate:",
  76. "Surround O&PL", "Music volume:", "Sound volume:","Buffer:", "Quality:",
  77. "E&xit", "&Launch game", "&Default", "Verbose|Debug|Informational|Warning|Error|Fatal" },
  78. { "SDLPAL 启动器", "字体及语言设置", "显示设置", "音频设置", "日志记录设置",
  79. "游戏资源目录:", "语言文件:", "字体文件", "日志文件", "日志记录级别:",
  80. "启用触屏辅助(&H)", "保持纵横比(&K)", "全屏模式(&F)", "AVI 动画(&V)", "&CD 音源:",
  81. "&BGM 音源:", "&OPL 类型:", "采样率:", "立体声(&R)", "OPL 采样率:",
  82. "环绕声 O&PL", "音乐音量:", "音效音量:", "缓冲区:", "质量:",
  83. "退出(&X)", "启动游戏(&L)", "默认设置(&D)", "详细信息|调试信息|运行信息|普通警告|严重错误|致命错误" },
  84. { "SDLPAL 啟動器", "字體及語言設定", "顯示設定", "音訊設定", "日誌記錄設定",
  85. "遊戲資源檔夾:", "語言檔:", "字體檔:", "日誌檔:", "日誌記錄級別:",
  86. "啟用觸屏輔助(&H)", "保持縱橫比(&K)", "全屏模式(&F)", "AVI 動畫(&V)", "&CD 音源:",
  87. "&BGM 音源:", "&OPL 類型:", "取樣速率:", "立體聲(&R)", "OPL 取樣速率:",
  88. "環繞聲 O&PL", "音樂音量:", "音效音量:", "緩衝區:", "品質:",
  89. "退出(&X)", "啟動遊戲(&L)", "默認設定(&D)", "詳細信息|調試信息|運行信息|普通警告|嚴重錯誤|致命錯誤" },
  90. };
  91. void InitControls()
  92. {
  93. char buffer[64];
  94. gWidgets.gamepath->value(gConfig.pszGamePath);
  95. gWidgets.msgfile->value(gConfig.pszMsgFile);
  96. gWidgets.fontfile->value(gConfig.pszFontFile);
  97. gWidgets.logfile->value(gConfig.pszLogFile);
  98. gWidgets.loglevel->value(gConfig.iLogLevel);
  99. gWidgets.touch->value(gConfig.fUseTouchOverlay ? 1 : 0);
  100. gWidgets.aspect->value(gConfig.fKeepAspectRatio ? 1 : 0);
  101. gWidgets.fullscreen->value(gConfig.fFullScreen ? 1 : 0);
  102. gWidgets.avi->value(gConfig.fEnableAviPlay ? 1 : 0);
  103. gWidgets.cd->value(gConfig.eCDType - MUSIC_MP3);
  104. gWidgets.bgm->value(gConfig.eMusicType);
  105. gWidgets.stereo->value(gConfig.iAudioChannels == 2 ? 1 : 0);
  106. sprintf(buffer, "%d", gConfig.iSampleRate); gWidgets.samplerate->value(buffer);
  107. gWidgets.opl->value(gConfig.eOPLType);
  108. sprintf(buffer, "%d", gConfig.iOPLSampleRate); gWidgets.oplrate->value(buffer);
  109. gWidgets.surround->value(gConfig.fUseSurroundOPL ? 1 : 0);
  110. sprintf(buffer, "%d", gConfig.wAudioBufferSize); gWidgets.buffer->value(buffer);
  111. gWidgets.quality->value(gConfig.iResampleQuality);
  112. gWidgets.music->value(gConfig.iMusicVolume);
  113. gWidgets.sound->value(gConfig.iSoundVolume);
  114. }
  115. void SaveControls()
  116. {
  117. free(gConfig.pszGamePath);
  118. free(gConfig.pszMsgFile);
  119. free(gConfig.pszFontFile);
  120. free(gConfig.pszLogFile);
  121. gConfig.pszGamePath = *gWidgets.gamepath->value() ? strdup(gWidgets.gamepath->value()) : nullptr;
  122. gConfig.pszMsgFile = *gWidgets.msgfile->value() ? strdup(gWidgets.msgfile->value()) : nullptr;
  123. gConfig.pszFontFile = *gWidgets.fontfile->value() ? strdup(gWidgets.fontfile->value()) : nullptr;
  124. gConfig.pszLogFile = *gWidgets.logfile->value() ? strdup(gWidgets.logfile->value()) : nullptr;
  125. gConfig.iLogLevel = (LOGLEVEL)gWidgets.loglevel->value();
  126. gConfig.fUseTouchOverlay = gWidgets.touch->value();
  127. gConfig.fKeepAspectRatio = gWidgets.aspect->value();
  128. gConfig.fFullScreen = gWidgets.fullscreen->value();
  129. gConfig.fEnableAviPlay = gWidgets.avi->value();
  130. gConfig.eCDType = (MUSICTYPE)(gWidgets.cd->value() + MUSIC_MP3);
  131. gConfig.eMusicType = (MUSICTYPE)(gWidgets.bgm->value());
  132. gConfig.iAudioChannels = gWidgets.stereo->value() ? 2 : 1;
  133. gConfig.iSampleRate = atoi(gWidgets.samplerate->value());
  134. gConfig.eOPLType = (OPLTYPE)gWidgets.opl->value();
  135. gConfig.iOPLSampleRate = atoi(gWidgets.oplrate->value());
  136. gConfig.fUseSurroundOPL = gWidgets.surround->value();
  137. gConfig.wAudioBufferSize = atoi(gWidgets.buffer->value());
  138. gConfig.iResampleQuality = (int)gWidgets.quality->value();
  139. gConfig.iMusicVolume = (int)gWidgets.music->value();
  140. gConfig.iSoundVolume = (int)gWidgets.sound->value();
  141. gConfig.fLaunchSetting = FALSE;
  142. }
  143. int GetLanguage()
  144. {
  145. auto lang = getenv("LANG");
  146. if (!lang) return 0;
  147. if (strncasecmp(lang, "zh_", 3) == 0)
  148. {
  149. if (strncasecmp(lang + 3, "hans", 4) == 0 || strncasecmp(lang + 3, "CN", 2) == 0 || strncasecmp(lang + 3, "SG", 2) == 0)
  150. return 1;
  151. else
  152. return 2;
  153. }
  154. else
  155. return 0;
  156. }
  157. Fl_Window* InitWindow()
  158. {
  159. int lang = GetLanguage();
  160. Fl_Window* window = new Fl_Window(640, 400, gLabels[lang].title);
  161. gWidgets.gamepath = new Fl_Input(160, 9, 475, 22, gLabels[lang].gamepath);
  162. (new Fl_Box(FL_BORDER_BOX, 5, 50, 630, 55, gLabels[lang].language))->align(FL_ALIGN_TOP);
  163. gWidgets.msgfile = new Fl_Input(109, 54, 516, 22, gLabels[lang].msgfile);
  164. gWidgets.fontfile = new Fl_Input(109, 79, 516, 22, gLabels[lang].fontfile);
  165. (new Fl_Box(FL_BORDER_BOX, 5, 127, 630, 30, gLabels[lang].logging))->align(FL_ALIGN_TOP);
  166. (gWidgets.loglevel = new Fl_Choice(85, 132, 120, 20, gLabels[lang].loglevel))->add(gLabels[lang].levels);
  167. gWidgets.logfile = new Fl_Input(284, 131, 341, 22, gLabels[lang].logfile);
  168. (new Fl_Box(FL_BORDER_BOX, 5, 180, 630, 30, gLabels[lang].display))->align(FL_ALIGN_TOP);
  169. gWidgets.touch = new Fl_Check_Button(10, 185, 150, 20, gLabels[lang].touch);
  170. gWidgets.aspect = new Fl_Check_Button(200, 185, 150, 20, gLabels[lang].aspect);
  171. gWidgets.avi = new Fl_Check_Button(390, 185, 100, 20, gLabels[lang].avi);
  172. gWidgets.fullscreen = new Fl_Check_Button(530, 185, 100, 20, gLabels[lang].fullscreen);
  173. (new Fl_Box(FL_BORDER_BOX, 5, 230, 630, 130, gLabels[lang].audio))->align(FL_ALIGN_TOP);
  174. (gWidgets.cd = new Fl_Choice(84, 239, lang ? 100 : 120, 22, gLabels[lang].cd))->add("MP3|OGG");
  175. (gWidgets.bgm = new Fl_Choice(285, 239, 60, 22, gLabels[lang].bgm))->add("MIDI|RIX|MP3|OGG");
  176. gWidgets.stereo = new Fl_Check_Button(365, 240, 70, 20, gLabels[lang].stereo);
  177. gWidgets.samplerate = new Fl_Int_Input(570, 239, 60, 22, gLabels[lang].samplerate);
  178. (gWidgets.opl = new Fl_Choice(84, 269, lang ? 100 : 120, 22, gLabels[lang].opl))->add("DOSBOX|MAME|DOSBOXNEW");
  179. gWidgets.oplrate = new Fl_Int_Input(285, 269, 60, 22, gLabels[lang].oplrate);
  180. gWidgets.surround = new Fl_Check_Button(365, 270, 120, 20, gLabels[lang].surround);
  181. gWidgets.buffer = new Fl_Int_Input(570, 269, 60, 22, gLabels[lang].buffer);
  182. gWidgets.quality = new Fl_Hor_Value_Slider(72, 299, 180, 22, gLabels[lang].quality);
  183. gWidgets.quality->align(FL_ALIGN_LEFT);
  184. gWidgets.quality->bounds(0, 4);
  185. gWidgets.quality->precision(0);
  186. gWidgets.music = new Fl_Hor_Value_Slider(380, 299, 250, 22, gLabels[lang].musvol);
  187. gWidgets.music->align(FL_ALIGN_LEFT);
  188. gWidgets.music->bounds(0, 100);
  189. gWidgets.music->precision(0);
  190. gWidgets.sound = new Fl_Hor_Value_Slider(380, 329, 250, 22, gLabels[lang].sndvol);
  191. gWidgets.sound->align(FL_ALIGN_LEFT);
  192. gWidgets.sound->bounds(0, 100);
  193. gWidgets.sound->precision(0);
  194. (new Fl_Button(5, 370, 120, 24, gLabels[lang].exit))->callback([](Fl_Widget* ctrl, void* window) {
  195. if (ctrl->when() == FL_WHEN_RELEASE)
  196. static_cast<Fl_Window*>(window)->hide();
  197. }, window);
  198. (new Fl_Button(260, 370, 120, 24, gLabels[lang].launch))->callback([](Fl_Widget* ctrl, void* window) {
  199. if (ctrl->when() == FL_WHEN_RELEASE) {
  200. SaveControls();
  201. PAL_SaveConfig();
  202. static_cast<Fl_Window*>(window)->hide();
  203. }
  204. }, window);
  205. (new Fl_Button(515, 370, 120, 24, gLabels[lang].def))->callback([](Fl_Widget*) { PAL_LoadConfig(FALSE); InitControls(); });
  206. window->end();
  207. InitControls();
  208. return window;
  209. }
  210. #endif
  211. BOOL
  212. UTIL_GetScreenSize(
  213. DWORD *pdwScreenWidth,
  214. DWORD *pdwScreenHeight
  215. )
  216. {
  217. return pdwScreenWidth && pdwScreenHeight && *pdwScreenWidth && *pdwScreenHeight;
  218. }
  219. BOOL
  220. UTIL_IsAbsolutePath(
  221. LPCSTR lpszFileName
  222. )
  223. {
  224. return lpszFileName && *lpszFileName == '/';
  225. }
  226. INT
  227. UTIL_Platform_Init(
  228. int argc,
  229. char* argv[]
  230. )
  231. {
  232. openlog("sdlpal", LOG_PERROR | LOG_PID, LOG_USER);
  233. UTIL_LogAddOutputCallback([](LOGLEVEL level, const char* str, const char*)->void {
  234. const static int priorities[] = {
  235. LOG_DEBUG,
  236. LOG_DEBUG,
  237. LOG_INFO,
  238. LOG_WARNING,
  239. LOG_ERR,
  240. LOG_EMERG
  241. };
  242. syslog(priorities[level], "%s", str);
  243. }, PAL_DEFAULT_LOGLEVEL);
  244. #if !defined(UNIT_TEST) && !defined(PAL_NO_LAUNCH_UI)
  245. if (gConfig.fLaunchSetting)
  246. {
  247. Fl_Window *window = InitWindow();
  248. window->show(argc, argv);
  249. Fl::run();
  250. Fl::flush();
  251. delete window;
  252. }
  253. #else
  254. gConfig.fLaunchSetting = FALSE;
  255. #endif
  256. return 0;
  257. }
  258. VOID
  259. UTIL_Platform_Quit(
  260. VOID
  261. )
  262. {
  263. closelog();
  264. }