obs-windows.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "util/platform.h"
  15. #include "util/dstr.h"
  16. #include "obs.h"
  17. #include "obs-internal.h"
  18. static inline bool check_path(const char* data, const char *path,
  19. struct dstr * output)
  20. {
  21. dstr_copy(output, path);
  22. dstr_cat(output, data);
  23. blog(LOG_INFO, "Attempting path: %s\n", output->array);
  24. return os_file_exists(output->array);
  25. }
  26. static inline bool check_lib_path(const char* data, const char *path,
  27. struct dstr *output)
  28. {
  29. bool result = false;
  30. struct dstr tmp;
  31. dstr_init_copy(&tmp, data);
  32. dstr_cat(&tmp, ".dll");
  33. result = check_path(tmp.array, path, output);
  34. dstr_free(&tmp);
  35. return result;
  36. }
  37. /* on windows, plugin files are located in [base directory]/plugins/[bit] */
  38. char *find_plugin(const char *plugin)
  39. {
  40. struct dstr path;
  41. dstr_init(&path);
  42. #ifdef _WIN64
  43. if (check_lib_path(plugin, "obs-plugins/64bit/", &path))
  44. #else
  45. if (check_lib_path(plugin, "obs-plugins/32bit/", &path))
  46. #endif
  47. return path.array;
  48. #ifdef _WIN64
  49. if (check_lib_path(plugin, "../../obs-plugins/64bit/", &path))
  50. #else
  51. if (check_lib_path(plugin, "../../obs-plugins/32bit/", &path))
  52. #endif
  53. return path.array;
  54. dstr_free(&path);
  55. return NULL;
  56. }
  57. /* on windows, points to [base directory]/libobs */
  58. char *find_libobs_data_file(const char *file)
  59. {
  60. struct dstr path;
  61. dstr_init(&path);
  62. if (check_path(file, "data/libobs/", &path))
  63. return path.array;
  64. if (check_path(file, "../../data/libobs/", &path))
  65. return path.array;
  66. dstr_free(&path);
  67. return NULL;
  68. }
  69. /* on windows, data files should always be in [base directory]/data */
  70. char *obs_find_plugin_file(const char *file)
  71. {
  72. struct dstr path;
  73. dstr_init(&path);
  74. if (check_path(file, "data/obs-plugins/", &path))
  75. return path.array;
  76. if (check_path(file, "../../data/obs-plugins/", &path))
  77. return path.array;
  78. dstr_free(&path);
  79. return NULL;
  80. }