public async Task <string> StoreFile(string filePath, bool publishAfterSave, CancellationToken cancellationToken, Action <double, string> progress) { // Compute SHA1 string sha1 = HashGenerator.ComputeFileSHA1(filePath); string sha1PlusExtension = sha1 + Path.GetExtension(filePath).ToLower(); string assetPath = Path.Combine(Object3D.AssetsPath, sha1PlusExtension); // Load cache if (!File.Exists(assetPath)) { File.Copy(filePath, assetPath); } if (publishAfterSave) { await Publish(sha1PlusExtension, cancellationToken, progress); } return(sha1PlusExtension); }
/// <summary> /// Returns the computed GCode path given a content file path and considering current settings /// </summary> /// <param name="printer">The associated printer</param> /// <param name="fileLocation">The source file</param> /// <returns>The target GCode path</returns> private async Task <string> GetGCodePath(PrinterConfig printer, string fileLocation) { if (fileLocation.Trim() != "") { if (Path.GetExtension(fileLocation).ToUpper() == ".GCODE") { return(fileLocation); } string fileHashCode = HashGenerator.ComputeFileSHA1(fileLocation); var fileExtension = Path.GetExtension(fileLocation).ToUpper(); if (fileExtension == ".MCX") { var hashCode = fileHashCode.GetLongHashCode(); var fileNames = GetFileNamesFromMcx(fileLocation); foreach (var file in fileNames) { var fullPath = await Object3DExtensions.ResolveFilePath(file, null, CancellationToken.None); if (File.Exists(fullPath)) { hashCode = File.GetLastWriteTime(fullPath).ToString().GetLongHashCode(hashCode); } } fileHashCode = hashCode.ToString(); } ulong settingsHashCode = printer.Settings.GetGCodeCacheKey(); return(Path.Combine( ApplicationDataStorage.Instance.GCodeOutputPath, $"{fileHashCode}_{ settingsHashCode}.gcode")); } else { return(null); } }