BOOL SoftwareList_AddFile(HWND hwndPicker,LPCSTR pszName, LPCSTR pszListname, LPCSTR pszDescription, LPCSTR pszPublisher, LPCSTR pszYear, LPCSTR pszUsage, LPCSTR pszDevice) { Picker_ResetIdle(hwndPicker); software_list_info *pPickerInfo; file_info **ppNewIndex; file_info *pInfo; int nIndex, nSize; // first check to see if it is already here //if (SoftwareList_LookupIndex(hwndPicker, pszName) >= 0) // return TRUE; pPickerInfo = GetSoftwareListInfo(hwndPicker); // create the FileInfo structure nSize = sizeof(file_info); pInfo = (file_info *) malloc(nSize); if (!pInfo) goto error; memset(pInfo, 0, nSize); // copy the filename strcpy(pInfo->file_name, pszName); strcpy(pInfo->list_name, pszListname); strcpy(pInfo->description, pszDescription); strcpy(pInfo->publisher, pszPublisher); strcpy(pInfo->year, pszYear); if (pszUsage) strcpy(pInfo->usage, pszUsage); strcpy(pInfo->device, pszDevice); sprintf(pInfo->full_name,"%s:%s", pszListname,pszName); ppNewIndex = (file_info**)malloc((pPickerInfo->file_index_length + 1) * sizeof(*pPickerInfo->file_index)); memcpy(ppNewIndex,pPickerInfo->file_index,pPickerInfo->file_index_length * sizeof(*pPickerInfo->file_index)); if (pPickerInfo->file_index) free(pPickerInfo->file_index); if (!ppNewIndex) goto error; nIndex = pPickerInfo->file_index_length++; pPickerInfo->file_index = ppNewIndex; pPickerInfo->file_index[nIndex] = pInfo; // Actually insert the item into the picker Picker_InsertItemSorted(hwndPicker, nIndex); software_numberofitems++; return TRUE; error: if (pInfo) free(pInfo); return FALSE; }
static BOOL SoftwarePicker_AddFileEntry(HWND hwndPicker, LPCSTR pszFilename, UINT nZipEntryNameLength, UINT32 nCrc, BOOL bForce) { software_picker_info *pPickerInfo; file_info **ppNewIndex; file_info *pInfo; int nIndex, nSize; LPCSTR pszExtension = NULL; const device_config_image_interface *device = NULL; // first check to see if it is already here if (SoftwarePicker_LookupIndex(hwndPicker, pszFilename) >= 0) return TRUE; pPickerInfo = GetSoftwarePickerInfo(hwndPicker); // look up the device if (strrchr(pszFilename, '.')) pszExtension = strrchr(pszFilename, '.'); if ((pszExtension != NULL) && (pPickerInfo->config != NULL)) { for (bool gotone = pPickerInfo->config->mconfig->m_devicelist.first(device); gotone; gotone = device->next(device)) { if (device->uses_file_extension(pszExtension)) { break; } } } // no device? cop out unless bForce is on if ((device == NULL) && !bForce) return TRUE; // create the FileInfo structure nSize = sizeof(file_info) + strlen(pszFilename); pInfo = (file_info *) malloc(nSize); if (!pInfo) goto error; memset(pInfo, 0, nSize); // copy the filename strcpy(pInfo->file_name, pszFilename); // set up device and CRC, if specified pInfo->device = device; if ((device != NULL) && (device->has_partial_hash() != 0)) nCrc = 0; //if (nCrc != 0) //snprintf(pInfo->hash_string, ARRAY_LENGTH(pInfo->hash_string), "c:%08x#", nCrc); // set up zip entry name length, if specified if (nZipEntryNameLength > 0) pInfo->zip_entry_name = pInfo->file_name + strlen(pInfo->file_name) - nZipEntryNameLength; // calculate the subname pInfo->base_name = strrchr(pInfo->file_name, '\\'); if (pInfo->base_name) pInfo->base_name++; else pInfo->base_name = pInfo->file_name; ppNewIndex = (file_info**)malloc((pPickerInfo->file_index_length + 1) * sizeof(*pPickerInfo->file_index)); memcpy(ppNewIndex,pPickerInfo->file_index,pPickerInfo->file_index_length * sizeof(*pPickerInfo->file_index)); if (pPickerInfo->file_index) free(pPickerInfo->file_index); if (!ppNewIndex) goto error; nIndex = pPickerInfo->file_index_length++; pPickerInfo->file_index = ppNewIndex; pPickerInfo->file_index[nIndex] = pInfo; // Realize the hash SoftwarePicker_RealizeHash(hwndPicker, nIndex); // Actually insert the item into the picker Picker_InsertItemSorted(hwndPicker, nIndex); return TRUE; error: if (pInfo) free(pInfo); return FALSE; }