Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.6KB

  1. #include <stdlib.h>
  2. #include <string.h>
  3. #ifdef WIN32
  4. # include <windows.h>
  5. #endif
  6. #include "appDetails.h"
  7. #define CMD_BUF_LEN 1024
  8. static int sfx_app_argc = 0;
  9. static char** sfx_app_argv = NULL;
  10. static char sfx_tmp_path[512] = { 0 };
  11. void sfx_app_set_args(int argc, char** argv)
  12. {
  13. sfx_app_argc = argc;
  14. sfx_app_argv = argv;
  15. }
  16. int sfx_app_autorun_now()
  17. {
  18. int i, cmdBufLen = 0;
  19. char cmdBuf[CMD_BUF_LEN];
  20. const char* const path = sfx_get_tmp_path(1);
  21. chdir(path);
  22. strcpy(cmdBuf, path);
  23. strcat(cmdBuf, SFX_AUTORUN_CMD);
  24. cmdBufLen = strlen(cmdBuf);
  25. for (i=0; i < sfx_app_argc; i++)
  26. {
  27. if (! sfx_app_argv[i])
  28. continue;
  29. cmdBufLen += strlen(sfx_app_argv[i]) + 1;
  30. if (cmdBufLen >= CMD_BUF_LEN-1)
  31. break;
  32. strcat(cmdBuf, " ");
  33. strcat(cmdBuf, sfx_app_argv[i]);
  34. }
  35. puts(SFX_APP_BANNER);
  36. printf("Launching: '%s'\n", cmdBuf);
  37. #ifdef WIN32
  38. ShellExecute(NULL, "open", cmdBuf, NULL, NULL, SW_SHOWNORMAL);
  39. return 0;
  40. #else
  41. const int ret = system(cmdBuf);
  42. exit(ret);
  43. return ret;
  44. #endif
  45. }
  46. char* sfx_get_tmp_path(int withAppName)
  47. {
  48. #ifdef WIN32
  49. {
  50. GetTempPathA(512 - strlen(SFX_APP_MININAME_TITLE), sfx_tmp_path);
  51. if (withAppName == 1)
  52. strcat(sfx_tmp_path, SFX_APP_MININAME_TITLE);
  53. }
  54. #else
  55. {
  56. char* tmp = getenv("TMP");
  57. if (tmp)
  58. strcpy(sfx_tmp_path, tmp);
  59. else
  60. strcpy(sfx_tmp_path, "/tmp");
  61. if (withAppName == 1)
  62. strcat(sfx_tmp_path, "/" SFX_APP_MININAME_LCASE);
  63. }
  64. #endif
  65. return sfx_tmp_path;
  66. }