FSAssetService.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Diagnostics;
  29. using System.Collections.Generic;
  30. using System.IO;
  31. using System.IO.Compression;
  32. using System.Text;
  33. using System.Threading;
  34. using System.Reflection;
  35. using OpenSim.Data;
  36. using OpenSim.Framework;
  37. using OpenSim.Framework.Serialization.External;
  38. using OpenSim.Framework.Console;
  39. using OpenSim.Server.Base;
  40. using OpenSim.Services.Base;
  41. using OpenSim.Services.Interfaces;
  42. using Nini.Config;
  43. using log4net;
  44. using OpenMetaverse;
  45. using System.Security.Cryptography;
  46. namespace OpenSim.Services.FSAssetService
  47. {
  48. public class FSAssetConnector : ServiceBase, IAssetService
  49. {
  50. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  51. static System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
  52. static SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider();
  53. static byte[] ToCString(string s)
  54. {
  55. byte[] ret = enc.GetBytes(s);
  56. Array.Resize(ref ret, ret.Length + 1);
  57. ret[ret.Length - 1] = 0;
  58. return ret;
  59. }
  60. protected IAssetLoader m_AssetLoader = null;
  61. protected IFSAssetDataPlugin m_DataConnector = null;
  62. protected IAssetService m_FallbackService;
  63. protected Thread m_WriterThread;
  64. protected Thread m_StatsThread;
  65. protected string m_SpoolDirectory;
  66. protected object m_readLock = new object();
  67. protected object m_statsLock = new object();
  68. protected int m_readCount = 0;
  69. protected int m_readTicks = 0;
  70. protected int m_missingAssets = 0;
  71. protected int m_missingAssetsFS = 0;
  72. protected string m_FSBase;
  73. private static bool m_Initialized;
  74. private bool m_MainInstance;
  75. public FSAssetConnector(IConfigSource config)
  76. : this(config, "AssetService")
  77. {
  78. }
  79. public FSAssetConnector(IConfigSource config, string configName) : base(config)
  80. {
  81. if (!m_Initialized)
  82. {
  83. m_Initialized = true;
  84. m_MainInstance = true;
  85. MainConsole.Instance.Commands.AddCommand("fs", false,
  86. "show assets", "show assets", "Show asset stats",
  87. HandleShowAssets);
  88. MainConsole.Instance.Commands.AddCommand("fs", false,
  89. "show digest", "show digest <ID>", "Show asset digest",
  90. HandleShowDigest);
  91. MainConsole.Instance.Commands.AddCommand("fs", false,
  92. "delete asset", "delete asset <ID>",
  93. "Delete asset from database",
  94. HandleDeleteAsset);
  95. MainConsole.Instance.Commands.AddCommand("fs", false,
  96. "import", "import <conn> <table> [<start> <count>]",
  97. "Import legacy assets",
  98. HandleImportAssets);
  99. MainConsole.Instance.Commands.AddCommand("fs", false,
  100. "force import", "force import <conn> <table> [<start> <count>]",
  101. "Import legacy assets, overwriting current content",
  102. HandleImportAssets);
  103. }
  104. IConfig assetConfig = config.Configs[configName];
  105. if (assetConfig == null)
  106. throw new Exception("No AssetService configuration");
  107. // Get Database Connector from Asset Config (If present)
  108. string dllName = assetConfig.GetString("StorageProvider", string.Empty);
  109. string m_ConnectionString = assetConfig.GetString("ConnectionString", string.Empty);
  110. string m_Realm = assetConfig.GetString("Realm", "fsassets");
  111. int SkipAccessTimeDays = assetConfig.GetInt("DaysBetweenAccessTimeUpdates", 0);
  112. // If not found above, fallback to Database defaults
  113. IConfig dbConfig = config.Configs["DatabaseService"];
  114. if (dbConfig != null)
  115. {
  116. if (dllName == String.Empty)
  117. dllName = dbConfig.GetString("StorageProvider", String.Empty);
  118. if (m_ConnectionString == String.Empty)
  119. m_ConnectionString = dbConfig.GetString("ConnectionString", String.Empty);
  120. }
  121. // No databse connection found in either config
  122. if (dllName.Equals(String.Empty))
  123. throw new Exception("No StorageProvider configured");
  124. if (m_ConnectionString.Equals(String.Empty))
  125. throw new Exception("Missing database connection string");
  126. // Create Storage Provider
  127. m_DataConnector = LoadPlugin<IFSAssetDataPlugin>(dllName);
  128. if (m_DataConnector == null)
  129. throw new Exception(string.Format("Could not find a storage interface in the module {0}", dllName));
  130. // Initialize DB And perform any migrations required
  131. m_DataConnector.Initialise(m_ConnectionString, m_Realm, SkipAccessTimeDays);
  132. // Setup Fallback Service
  133. string str = assetConfig.GetString("FallbackService", string.Empty);
  134. if (str != string.Empty)
  135. {
  136. object[] args = new object[] { config };
  137. m_FallbackService = LoadPlugin<IAssetService>(str, args);
  138. if (m_FallbackService != null)
  139. {
  140. m_log.Info("[FSASSETS]: Fallback service loaded");
  141. }
  142. else
  143. {
  144. m_log.Error("[FSASSETS]: Failed to load fallback service");
  145. }
  146. }
  147. // Setup directory structure including temp directory
  148. m_SpoolDirectory = assetConfig.GetString("SpoolDirectory", "/tmp");
  149. string spoolTmp = Path.Combine(m_SpoolDirectory, "spool");
  150. Directory.CreateDirectory(spoolTmp);
  151. m_FSBase = assetConfig.GetString("BaseDirectory", String.Empty);
  152. if (m_FSBase == String.Empty)
  153. {
  154. m_log.ErrorFormat("[FSASSETS]: BaseDirectory not specified");
  155. throw new Exception("Configuration error");
  156. }
  157. if (m_MainInstance)
  158. {
  159. string loader = assetConfig.GetString("DefaultAssetLoader", string.Empty);
  160. if (loader != string.Empty)
  161. {
  162. m_AssetLoader = LoadPlugin<IAssetLoader>(loader);
  163. string loaderArgs = assetConfig.GetString("AssetLoaderArgs", string.Empty);
  164. m_log.InfoFormat("[FSASSETS]: Loading default asset set from {0}", loaderArgs);
  165. m_AssetLoader.ForEachDefaultXmlAsset(loaderArgs,
  166. delegate(AssetBase a)
  167. {
  168. Store(a, false);
  169. });
  170. }
  171. m_WriterThread = new Thread(Writer);
  172. m_WriterThread.Start();
  173. m_StatsThread = new Thread(Stats);
  174. m_StatsThread.Start();
  175. }
  176. m_log.Info("[FSASSETS]: FS asset service enabled");
  177. }
  178. private void Stats()
  179. {
  180. while (true)
  181. {
  182. Thread.Sleep(60000);
  183. lock (m_statsLock)
  184. {
  185. if (m_readCount > 0)
  186. {
  187. double avg = (double)m_readTicks / (double)m_readCount;
  188. // if (avg > 10000)
  189. // Environment.Exit(0);
  190. m_log.InfoFormat("[FSASSETS]: Read stats: {0} files, {1} ticks, avg {2:F2}, missing {3}, FS {4}", m_readCount, m_readTicks, (double)m_readTicks / (double)m_readCount, m_missingAssets, m_missingAssetsFS);
  191. }
  192. m_readCount = 0;
  193. m_readTicks = 0;
  194. m_missingAssets = 0;
  195. m_missingAssetsFS = 0;
  196. }
  197. }
  198. }
  199. private void Writer()
  200. {
  201. m_log.Info("[FSASSETS]: Writer started");
  202. while (true)
  203. {
  204. string[] files = Directory.GetFiles(m_SpoolDirectory);
  205. if (files.Length > 0)
  206. {
  207. int tickCount = Environment.TickCount;
  208. for (int i = 0 ; i < files.Length ; i++)
  209. {
  210. string hash = Path.GetFileNameWithoutExtension(files[i]);
  211. string s = HashToFile(hash);
  212. string diskFile = Path.Combine(m_FSBase, s);
  213. Directory.CreateDirectory(Path.GetDirectoryName(diskFile));
  214. try
  215. {
  216. byte[] data = File.ReadAllBytes(files[i]);
  217. using (GZipStream gz = new GZipStream(new FileStream(diskFile + ".gz", FileMode.Create), CompressionMode.Compress))
  218. {
  219. gz.Write(data, 0, data.Length);
  220. gz.Close();
  221. }
  222. File.Delete(files[i]);
  223. //File.Move(files[i], diskFile);
  224. }
  225. catch(System.IO.IOException e)
  226. {
  227. if (e.Message.StartsWith("Win32 IO returned ERROR_ALREADY_EXISTS"))
  228. File.Delete(files[i]);
  229. else
  230. throw;
  231. }
  232. }
  233. int totalTicks = System.Environment.TickCount - tickCount;
  234. if (totalTicks > 0) // Wrap?
  235. {
  236. m_log.InfoFormat("[FSASSETS]: Write cycle complete, {0} files, {1} ticks, avg {2:F2}", files.Length, totalTicks, (double)totalTicks / (double)files.Length);
  237. }
  238. }
  239. Thread.Sleep(1000);
  240. }
  241. }
  242. string GetSHA256Hash(byte[] data)
  243. {
  244. byte[] hash = SHA256.ComputeHash(data);
  245. return BitConverter.ToString(hash).Replace("-", String.Empty);
  246. }
  247. public string HashToPath(string hash)
  248. {
  249. if (hash == null || hash.Length < 10)
  250. return "junkyard";
  251. return Path.Combine(hash.Substring(0, 3),
  252. Path.Combine(hash.Substring(3, 3)));
  253. /*
  254. * The below is what core would normally use.
  255. * This is modified to work in OSGrid, as seen
  256. * above, because the SRAS data is structured
  257. * that way.
  258. */
  259. /*
  260. return Path.Combine(hash.Substring(0, 2),
  261. Path.Combine(hash.Substring(2, 2),
  262. Path.Combine(hash.Substring(4, 2),
  263. hash.Substring(6, 4))));
  264. */
  265. }
  266. private bool AssetExists(string hash)
  267. {
  268. string s = HashToFile(hash);
  269. string diskFile = Path.Combine(m_FSBase, s);
  270. if (File.Exists(diskFile + ".gz") || File.Exists(diskFile))
  271. return true;
  272. return false;
  273. }
  274. public virtual bool[] AssetsExist(string[] ids)
  275. {
  276. UUID[] uuid = Array.ConvertAll(ids, id => UUID.Parse(id));
  277. return m_DataConnector.AssetsExist(uuid);
  278. }
  279. public string HashToFile(string hash)
  280. {
  281. return Path.Combine(HashToPath(hash), hash);
  282. }
  283. public virtual AssetBase Get(string id)
  284. {
  285. string hash;
  286. return Get(id, out hash);
  287. }
  288. private AssetBase Get(string id, out string sha)
  289. {
  290. string hash = string.Empty;
  291. int startTime = System.Environment.TickCount;
  292. AssetMetadata metadata;
  293. lock (m_readLock)
  294. {
  295. metadata = m_DataConnector.Get(id, out hash);
  296. }
  297. sha = hash;
  298. if (metadata == null)
  299. {
  300. AssetBase asset = null;
  301. if (m_FallbackService != null)
  302. {
  303. asset = m_FallbackService.Get(id);
  304. if (asset != null)
  305. {
  306. asset.Metadata.ContentType =
  307. SLUtil.SLAssetTypeToContentType((int)asset.Type);
  308. sha = GetSHA256Hash(asset.Data);
  309. m_log.InfoFormat("[FSASSETS]: Added asset {0} from fallback to local store", id);
  310. Store(asset);
  311. }
  312. }
  313. if (asset == null)
  314. {
  315. // m_log.InfoFormat("[FSASSETS]: Asset {0} not found", id);
  316. m_missingAssets++;
  317. }
  318. return asset;
  319. }
  320. AssetBase newAsset = new AssetBase();
  321. newAsset.Metadata = metadata;
  322. try
  323. {
  324. newAsset.Data = GetFsData(hash);
  325. if (newAsset.Data.Length == 0)
  326. {
  327. AssetBase asset = null;
  328. if (m_FallbackService != null)
  329. {
  330. asset = m_FallbackService.Get(id);
  331. if (asset != null)
  332. {
  333. asset.Metadata.ContentType =
  334. SLUtil.SLAssetTypeToContentType((int)asset.Type);
  335. sha = GetSHA256Hash(asset.Data);
  336. m_log.InfoFormat("[FSASSETS]: Added asset {0} from fallback to local store", id);
  337. Store(asset);
  338. }
  339. }
  340. if (asset == null)
  341. m_missingAssetsFS++;
  342. // m_log.InfoFormat("[FSASSETS]: Asset {0}, hash {1} not found in FS", id, hash);
  343. else
  344. {
  345. // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
  346. // Fix bad assets before sending them elsewhere
  347. if (asset.Type == (int)AssetType.Object && asset.Data != null)
  348. {
  349. string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
  350. asset.Data = Utils.StringToBytes(xml);
  351. }
  352. return asset;
  353. }
  354. }
  355. lock (m_statsLock)
  356. {
  357. m_readTicks += Environment.TickCount - startTime;
  358. m_readCount++;
  359. }
  360. // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
  361. // Fix bad assets before sending them elsewhere
  362. if (newAsset.Type == (int)AssetType.Object && newAsset.Data != null)
  363. {
  364. string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(newAsset.Data));
  365. newAsset.Data = Utils.StringToBytes(xml);
  366. }
  367. return newAsset;
  368. }
  369. catch (Exception exception)
  370. {
  371. m_log.Error(exception.ToString());
  372. Thread.Sleep(5000);
  373. Environment.Exit(1);
  374. return null;
  375. }
  376. }
  377. public virtual AssetMetadata GetMetadata(string id)
  378. {
  379. string hash;
  380. return m_DataConnector.Get(id, out hash);
  381. }
  382. public virtual byte[] GetData(string id)
  383. {
  384. string hash;
  385. if (m_DataConnector.Get(id, out hash) == null)
  386. return null;
  387. return GetFsData(hash);
  388. }
  389. public bool Get(string id, Object sender, AssetRetrieved handler)
  390. {
  391. AssetBase asset = Get(id);
  392. handler(id, sender, asset);
  393. return true;
  394. }
  395. public byte[] GetFsData(string hash)
  396. {
  397. string spoolFile = Path.Combine(m_SpoolDirectory, hash + ".asset");
  398. if (File.Exists(spoolFile))
  399. {
  400. try
  401. {
  402. byte[] content = File.ReadAllBytes(spoolFile);
  403. return content;
  404. }
  405. catch
  406. {
  407. }
  408. }
  409. string file = HashToFile(hash);
  410. string diskFile = Path.Combine(m_FSBase, file);
  411. if (File.Exists(diskFile + ".gz"))
  412. {
  413. try
  414. {
  415. using (GZipStream gz = new GZipStream(new FileStream(diskFile + ".gz", FileMode.Open, FileAccess.Read), CompressionMode.Decompress))
  416. {
  417. using (MemoryStream ms = new MemoryStream())
  418. {
  419. byte[] data = new byte[32768];
  420. int bytesRead;
  421. do
  422. {
  423. bytesRead = gz.Read(data, 0, 32768);
  424. if (bytesRead > 0)
  425. ms.Write(data, 0, bytesRead);
  426. } while (bytesRead > 0);
  427. return ms.ToArray();
  428. }
  429. }
  430. }
  431. catch (Exception)
  432. {
  433. return new Byte[0];
  434. }
  435. }
  436. else if (File.Exists(diskFile))
  437. {
  438. try
  439. {
  440. byte[] content = File.ReadAllBytes(diskFile);
  441. return content;
  442. }
  443. catch
  444. {
  445. }
  446. }
  447. return new Byte[0];
  448. }
  449. public virtual string Store(AssetBase asset)
  450. {
  451. return Store(asset, false);
  452. }
  453. private string Store(AssetBase asset, bool force)
  454. {
  455. int tickCount = Environment.TickCount;
  456. string hash = GetSHA256Hash(asset.Data);
  457. if (!AssetExists(hash))
  458. {
  459. string tempFile = Path.Combine(Path.Combine(m_SpoolDirectory, "spool"), hash + ".asset");
  460. string finalFile = Path.Combine(m_SpoolDirectory, hash + ".asset");
  461. if (!File.Exists(finalFile))
  462. {
  463. // Deal with bug introduced in Oct. 20 (1eb3e6cc43e2a7b4053bc1185c7c88e22356c5e8)
  464. // Fix bad assets before storing on this server
  465. if (asset.Type == (int)AssetType.Object && asset.Data != null)
  466. {
  467. string xml = ExternalRepresentationUtils.SanitizeXml(Utils.BytesToString(asset.Data));
  468. asset.Data = Utils.StringToBytes(xml);
  469. }
  470. FileStream fs = File.Create(tempFile);
  471. fs.Write(asset.Data, 0, asset.Data.Length);
  472. fs.Close();
  473. File.Move(tempFile, finalFile);
  474. }
  475. }
  476. if (asset.ID == string.Empty)
  477. {
  478. if (asset.FullID == UUID.Zero)
  479. {
  480. asset.FullID = UUID.Random();
  481. }
  482. asset.ID = asset.FullID.ToString();
  483. }
  484. else if (asset.FullID == UUID.Zero)
  485. {
  486. UUID uuid = UUID.Zero;
  487. if (UUID.TryParse(asset.ID, out uuid))
  488. {
  489. asset.FullID = uuid;
  490. }
  491. else
  492. {
  493. asset.FullID = UUID.Random();
  494. }
  495. }
  496. if (!m_DataConnector.Store(asset.Metadata, hash))
  497. {
  498. return UUID.Zero.ToString();
  499. }
  500. else
  501. {
  502. return asset.ID;
  503. }
  504. }
  505. public bool UpdateContent(string id, byte[] data)
  506. {
  507. return false;
  508. // string oldhash;
  509. // AssetMetadata meta = m_DataConnector.Get(id, out oldhash);
  510. //
  511. // if (meta == null)
  512. // return false;
  513. //
  514. // AssetBase asset = new AssetBase();
  515. // asset.Metadata = meta;
  516. // asset.Data = data;
  517. //
  518. // Store(asset);
  519. //
  520. // return true;
  521. }
  522. public virtual bool Delete(string id)
  523. {
  524. m_DataConnector.Delete(id);
  525. return true;
  526. }
  527. private void HandleShowAssets(string module, string[] args)
  528. {
  529. int num = m_DataConnector.Count();
  530. MainConsole.Instance.Output(string.Format("Total asset count: {0}", num));
  531. }
  532. private void HandleShowDigest(string module, string[] args)
  533. {
  534. if (args.Length < 3)
  535. {
  536. MainConsole.Instance.Output("Syntax: show digest <ID>");
  537. return;
  538. }
  539. string hash;
  540. AssetBase asset = Get(args[2], out hash);
  541. if (asset == null || asset.Data.Length == 0)
  542. {
  543. MainConsole.Instance.Output("Asset not found");
  544. return;
  545. }
  546. int i;
  547. MainConsole.Instance.Output(String.Format("Name: {0}", asset.Name));
  548. MainConsole.Instance.Output(String.Format("Description: {0}", asset.Description));
  549. MainConsole.Instance.Output(String.Format("Type: {0}", asset.Type));
  550. MainConsole.Instance.Output(String.Format("Content-type: {0}", asset.Metadata.ContentType));
  551. MainConsole.Instance.Output(String.Format("Flags: {0}", asset.Metadata.Flags.ToString()));
  552. MainConsole.Instance.Output(String.Format("FS file: {0}", HashToFile(hash)));
  553. for (i = 0 ; i < 5 ; i++)
  554. {
  555. int off = i * 16;
  556. if (asset.Data.Length <= off)
  557. break;
  558. int len = 16;
  559. if (asset.Data.Length < off + len)
  560. len = asset.Data.Length - off;
  561. byte[] line = new byte[len];
  562. Array.Copy(asset.Data, off, line, 0, len);
  563. string text = BitConverter.ToString(line);
  564. MainConsole.Instance.Output(String.Format("{0:x4}: {1}", off, text));
  565. }
  566. }
  567. private void HandleDeleteAsset(string module, string[] args)
  568. {
  569. if (args.Length < 3)
  570. {
  571. MainConsole.Instance.Output("Syntax: delete asset <ID>");
  572. return;
  573. }
  574. AssetBase asset = Get(args[2]);
  575. if (asset == null || asset.Data.Length == 0)
  576. {
  577. MainConsole.Instance.Output("Asset not found");
  578. return;
  579. }
  580. m_DataConnector.Delete(args[2]);
  581. MainConsole.Instance.Output("Asset deleted");
  582. }
  583. private void HandleImportAssets(string module, string[] args)
  584. {
  585. bool force = false;
  586. if (args[0] == "force")
  587. {
  588. force = true;
  589. List<string> list = new List<string>(args);
  590. list.RemoveAt(0);
  591. args = list.ToArray();
  592. }
  593. if (args.Length < 3)
  594. {
  595. MainConsole.Instance.Output("Syntax: import <conn> <table> [<start> <count>]");
  596. }
  597. else
  598. {
  599. string conn = args[1];
  600. string table = args[2];
  601. int start = 0;
  602. int count = -1;
  603. if (args.Length > 3)
  604. {
  605. start = Convert.ToInt32(args[3]);
  606. }
  607. if (args.Length > 4)
  608. {
  609. count = Convert.ToInt32(args[4]);
  610. }
  611. m_DataConnector.Import(conn, table, start, count, force, new FSStoreDelegate(Store));
  612. }
  613. }
  614. public AssetBase GetCached(string id)
  615. {
  616. return Get(id);
  617. }
  618. }
  619. }