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.

93 lines
1.8KB

  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. char magicBuf[512];
  43. strcpy(magicBuf, path);
  44. strcat(magicBuf, "magic.mgc");
  45. setenv("CARLA_MAGIC_FILE", magicBuf, 1);
  46. const int ret = system(cmdBuf);
  47. exit(ret);
  48. return ret;
  49. #endif
  50. }
  51. char* sfx_get_tmp_path(int withAppName)
  52. {
  53. #ifdef WIN32
  54. {
  55. GetTempPathA(512 - strlen(SFX_APP_MININAME_TITLE), sfx_tmp_path);
  56. if (withAppName == 1)
  57. strcat(sfx_tmp_path, SFX_APP_MININAME_TITLE "-2.1");
  58. }
  59. #else
  60. {
  61. char* tmp = getenv("TMP");
  62. if (tmp)
  63. strcpy(sfx_tmp_path, tmp);
  64. else
  65. strcpy(sfx_tmp_path, "/tmp");
  66. if (withAppName == 1)
  67. strcat(sfx_tmp_path, "/" SFX_APP_MININAME_LCASE "-2.1");
  68. }
  69. #endif
  70. return sfx_tmp_path;
  71. }