csstore.cpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* UIKit Tools - command-line utilities for UIKit
  2. * Copyright (C) 2018-2019 Sam Bingner
  3. * Copyright (C) 2008-2012 Jay Freeman (saurik)
  4. */
  5. /* This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /* Modified BSD License {{{ */
  19. /*
  20. * Redistribution and use in source and binary
  21. * forms, with or without modification, are permitted
  22. * provided that the following conditions are met:
  23. *
  24. * 1. Redistributions of source code must retain the
  25. * above copyright notice, this list of conditions
  26. * and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the
  28. * above copyright notice, this list of conditions
  29. * and the following disclaimer in the documentation
  30. * and/or other materials provided with the
  31. * distribution.
  32. * 3. The name of the author may not be used to endorse
  33. * or promote products derived from this software
  34. * without specific prior written permission.
  35. *
  36. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS''
  37. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  38. * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  39. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  40. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE
  41. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  42. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  43. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  44. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  45. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  46. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  47. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  48. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  49. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50. */
  51. /* }}} */
  52. #include <stdio.h>
  53. #include <stdlib.h>
  54. #include <string.h>
  55. #include <unistd.h>
  56. #include <sys/types.h>
  57. #include <dirent.h>
  58. bool DeleteCSStores(const char *home) {
  59. char path[strlen(home) + strlen("/Library/Caches") + 1];
  60. sprintf(path, "%s/Library/Caches", home);
  61. DIR *dir(opendir(path));
  62. if (dir == NULL)
  63. return false;
  64. for (struct dirent *entry; (entry = readdir(dir)) != NULL; ) {
  65. if (strncmp(entry->d_name, "com.apple.LaunchServices", sizeof("com.apple.LaunchServices") - 1) != 0)
  66. continue;
  67. if (!strstr(entry->d_name, ".csstore"))
  68. continue;
  69. char csstore[strlen(path) + 1 + strlen(entry->d_name) + 1];
  70. snprintf(csstore, sizeof(csstore), "%s/%s", path, entry->d_name);
  71. unlink(csstore);
  72. }
  73. closedir(dir);
  74. return true;
  75. }