SkinList.cpp
上传用户:lusi_8715
上传日期:2007-01-08
资源大小:199k
文件大小:5k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /**************************************************************************************
  2.  *                                                                                    *
  3.  * This application contains code from OpenDivX and is released as a "Larger Work"    *
  4.  * under that license. Consistant with that license, this application is released     *
  5.  * under the GNU General Public License.                                              *
  6.  *                                                                                    *
  7.  * The OpenDivX license can be found at: http://www.projectmayo.com/opendivx/docs.php *
  8.  * The GPL can be found at: http://www.gnu.org/copyleft/gpl.html                      *
  9.  *                                                                                    *
  10.  * Copyright (c) 2001 - Project Mayo                                                  *
  11.  *                                                                                    *
  12.  * Authors: Damien Chavarria <adrc at projectmayo.com>                                *
  13.  *                                                                                    *
  14.  **************************************************************************************/
  15. #include "SkinList.h"
  16. #include <windows.h>
  17. #include <string.h>
  18. #include <stdlib.h>
  19. /* 
  20.  * SkinInfo class
  21.  */
  22. SkinInfo::SkinInfo(char *directory) {
  23. this->directory = (char *) malloc(strlen(directory));
  24. this->directory = strcpy(this->directory, directory);
  25. this->name      = strrchr(this->directory, '\') + 1;
  26. if(name == NULL) {
  27. name = directory;
  28. }
  29. }
  30. SkinInfo::~SkinInfo() {
  31. free(this->directory);
  32. }
  33. /* 
  34.  * SkinList Class
  35.  */
  36. SkinList::SkinList() {
  37. this->totalSkins = 0;
  38. this->skins      = NULL;
  39. this->skinsDir   = NULL;
  40. /*
  41.  * Get the list of directories from the Registry
  42.  */
  43. HKEY     key;
  44. DWORD    created, size, type;
  45. LONG     result;
  46. /*
  47.  * Open the registry key
  48.  */
  49. result = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\DivXNetworks\ThePlaya",
  50. 0, "CONFIG", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 
  51. NULL, &key, &created);
  52. if(result != ERROR_SUCCESS) {
  53. MessageBox(NULL, "Couldn't load skins directories", "", MB_OK);
  54. return;
  55. }
  56. switch(created) {
  57. case REG_CREATED_NEW_KEY:
  58. /*
  59.  * First time launch (we keep the default)
  60.  * 
  61.  */
  62. this->skinsDir = NULL;
  63. break;
  64. case REG_OPENED_EXISTING_KEY:
  65. /*
  66.  * We can read the values
  67.    */
  68. this->skinsDir = (char *) malloc(65536);
  69. size = 65536;
  70. result = RegQueryValueEx(key, "SkinsDir", 0, &type, (BYTE *)this->skinsDir, &size);
  71. if(result == ERROR_MORE_DATA) {
  72. this->skinsDir = (char *) realloc(this->skinsDir, size);
  73. result = RegQueryValueEx(key, "SkinsDir", 0, &type, (BYTE *)this->skinsDir, &size);
  74. }
  75. if(result != ERROR_SUCCESS) {
  76. free(this->skinsDir);
  77. this->skinsDir = NULL;
  78. }
  79. break;
  80. default:
  81. break;
  82. }
  83. RegCloseKey(key);
  84. }
  85. SkinList::~SkinList() {
  86. free(this->skinsDir);
  87. }
  88. void SkinList::Add(SkinInfo *skinInfo) {
  89. skinlist_t *node;
  90. node = (skinlist_t *) malloc(sizeof(skinlist_t));
  91. node->info     = skinInfo;
  92. node->next     = this->skins;
  93. this->skins = node;
  94. this->totalSkins++;
  95. }
  96. int SkinList::SetDir(char *dir) {
  97. this->skinsDir = dir;
  98. HKEY     key;
  99. DWORD    created;
  100. LONG     result;
  101. /*
  102.  * Try to open the registry key
  103.  */
  104. result = RegCreateKeyEx(HKEY_CURRENT_USER, "Software\DivXNetworks\ThePlaya",
  105. 0, "CONFIG", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 
  106. NULL, &key, &created);
  107. if(result != ERROR_SUCCESS) {
  108. MessageBox(NULL, "Couldn't save skins dir", "", MB_OK);
  109. return 0;
  110. }
  111. RegSetValueEx(key, "SkinsDir", 0, REG_SZ, (BYTE *) this->skinsDir, strlen(this->skinsDir));
  112. return 1;
  113. }
  114. int SkinList::Scan() {
  115. this->totalSkins = 0;
  116. this->skins      = NULL;
  117. if(this->skinsDir != NULL && strcmp(this->skinsDir, "Default") != 0) {
  118. WIN32_FIND_DATA dirData, skinData;
  119. HANDLE          hFind = NULL, hSkin = NULL;
  120. char           *str, *str2;
  121. str = (char *) malloc(strlen(this->skinsDir));
  122. strcpy(str, this->skinsDir);
  123. hFind = FindFirstFile(strcat(str, "\*.*"), &dirData);
  124. if(hFind != NULL) {
  125. if(strcmp(dirData.cFileName, ".") != 0 && strcmp(dirData.cFileName, "..") != 0) {
  126. if(dirData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  127. this->Add(new SkinInfo(dirData.cFileName));
  128. }
  129. }
  130. while(FindNextFile(hFind, &dirData)) {
  131. if(strcmp(dirData.cFileName, ".") != 0 && strcmp(dirData.cFileName, "..") != 0) {
  132. if(dirData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  133. char filename[65535];
  134. strcpy(filename, this->skinsDir);
  135. this->Add(new SkinInfo(strcat(strcat(filename, "\"), dirData.cFileName)));
  136. }
  137. }
  138. }
  139. FindClose(hFind);
  140. }
  141. }
  142. return 0;
  143. }
  144. int Reset() {
  145. return 0;
  146. }
  147. int SkinList::getNumberOfSkins() {
  148. return this->totalSkins;
  149. }
  150. SkinInfo *SkinList::getSkinInfo(int position) {
  151. if(position >= 0 && position < this->totalSkins) {
  152. int         i;
  153. skinlist_t *node;
  154. node = this->skins;
  155. for(i = 0; i < position; i++) {
  156. node = node->next;
  157. }
  158. return node->info;
  159. }
  160. return NULL;
  161. }