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.

88 lines
1.6KB

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