| 806 | #if USE_EDITOR |
| 807 | |
| 808 | bool FlaxStorage::ChangeAssetID(Entry& e, const Guid& newId) |
| 809 | { |
| 810 | ASSERT(IsLoaded()); |
| 811 | |
| 812 | // TODO: validate entry |
| 813 | ASSERT(newId.IsValid()); |
| 814 | ASSERT(!IsReadOnly()); |
| 815 | |
| 816 | LOG(Info, "Changing asset \'{0}\' id to \'{1}\' (storage: \'{2}\')", e.ID, newId, _path); |
| 817 | |
| 818 | // Ensure to be loaded |
| 819 | if (!IsLoaded()) |
| 820 | { |
| 821 | if (Load()) |
| 822 | { |
| 823 | return true; |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | // Load asset entries data |
| 828 | int32 entriesCount = GetEntriesCount(); |
| 829 | Array<AssetInitData> data; |
| 830 | data.Resize(entriesCount); |
| 831 | for (int32 i = 0; i < entriesCount; i++) |
| 832 | { |
| 833 | if (LoadAssetHeader(i, data[i])) |
| 834 | { |
| 835 | LOG(Warning, "Cannot load asset data."); |
| 836 | return true; |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | // Load all chunks |
| 841 | for (int32 i = 0; i < _chunks.Count(); i++) |
| 842 | { |
| 843 | if (LoadAssetChunk(_chunks[i])) |
| 844 | { |
| 845 | LOG(Warning, "Cannot load asset chunk."); |
| 846 | return true; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | // Close file |
| 851 | if (CloseFileHandles()) |
| 852 | { |
| 853 | LOG(Error, "Cannot close file access for '{}'", _path); |
| 854 | return true; |
| 855 | } |
| 856 | |
| 857 | // Change ID |
| 858 | // TODO: here we could extend it and load assets from the storage and call asset ID change event to change references |
| 859 | Array<Entry> entries; |
| 860 | GetEntries(entries); |
| 861 | for (int32 i = 0; i < entriesCount; i++) |
| 862 | { |
| 863 | Entry* myE = &entries[i]; |
| 864 | if (myE->ID == e.ID) |
| 865 | { |