/// <summary> /// Serves as a hash function for a particular type. /// </summary> /// <returns>A hash code for the current <see cref="T:System.Object" />.</returns> public override int GetHashCode() { return((string.IsNullOrWhiteSpace(ImageFilePath) ? 0 : ImageFilePath.GetHashCode()) ^ MountMode.GetHashCode() ^ (string.IsNullOrWhiteSpace(MountPath) ? 0 : MountPath.GetHashCode()) ^ MountStatus.GetHashCode()); }
protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken) { // Inputs var timeout = TimeoutMS.Get(context); var imageFilePath = ImageFilePath.Get(context); if (!File.Exists(imageFilePath)) { throw new FileNotFoundException(imageFilePath); } if (!Directory.Exists(Path.GetDirectoryName(imageFilePath))) { throw new ArgumentException(string.Format(Resources.ValidationValueFullPath_Error, Resources.ChangeWallpaper_ImageFilePath_DisplayName)); } // Set a timeout on the execution var task = ExecuteWithTimeout(context, cancellationToken); if (await Task.WhenAny(task, Task.Delay(timeout, cancellationToken)) != task) { throw new TimeoutException(Resources.Timeout_Error); } // Outputs return((ctx) => { Result.Set(ctx, task.Result); }); }
private async Task <bool> ExecuteWithTimeout(AsyncCodeActivityContext context, CancellationToken cancellationToken = default) { var imagefilepath = ImageFilePath.Get(context); var outputfilepath = OutputFilePath.Get(context); var text = Text.Get(context); var fontsize = FontSize.Get(context); var fontname = FontName.Get(context); return(await Task.FromResult(new WallpaperGenerater().GenerateWallPaperFromFile(imagefilepath, TextColor, text, fontsize, fontname, outputfilepath))); }
private bool CanAddPoI() { if (string.IsNullOrEmpty(ImageFilePath) || ImageFilePath.Equals(BASE_IMAGE_SELECTER)) { return(false); } if (string.IsNullOrEmpty(Name)) { return(false); } if (string.IsNullOrEmpty(Tag)) { return(false); } if (string.IsNullOrEmpty(Description)) { return(false); } return(true); }
private void SaveLayersToPNGs_imple(string prePath, List <Layer> layers) { var psdFileStream = new FileStream(this.PsdFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); foreach (var layer in layers) { if (!layer.canLoadLayer) { continue; } if (layer.isContainer) { this.SaveLayersToPNGs_imple(prePath + "/" + layer.name, layer.children); continue; } var pa = new PsdLayerCommandParser.ControlParser(prePath, layer); if (pa.type == PsdLayerCommandParser.ControlType.Script || pa.type == PsdLayerCommandParser.ControlType.Label || pa.type == PsdLayerCommandParser.ControlType.LabelButton) { continue; } var fileName = pa.fullName; if (this.HasUnacceptibleChar(fileName)) { Debug.LogError(fileName + " Contains wrong character '\\ / : * ? \" < > |' not allowed"); continue; } var filePath = prePath + "/" + fileName + ".png"; ImageFilePath newImageFilePath = null; { try { psdFileStream.Position = 0; var br = new BinaryReader(psdFileStream); { layer.LoadData(br, this.Psd.headerInfo.bpp); newImageFilePath = new ImageFilePath(filePath, "pass"); } } catch (System.Exception e) { Debug.LogError(e.Message); } } this.ImageFilePathes.Add(newImageFilePath); //**md5: too slow // ImageFilePath lastImageFilePath = null; // ImageFilePath newImageFilePath = null; // { // try // { // if (this.LastImageFilePathes != null && this.LastImageFilePathes.Count > 0) // { // lastImageFilePath = this.LastImageFilePathes.Find(t=>t.filePath == filePath); // } // // psdFileStream.Position = 0; // var br = new BinaryReader(psdFileStream); // { // layer.LoadData(br, this.Psd.headerInfo.bpp); // var imageMd5 = this.CalcMd5Imple(br.BaseStream); // var imageMd5 = "pass"; // newImageFilePath = new ImageFilePath(filePath, imageMd5); // } // } // catch (System.Exception e) // { // Debug.LogError(e.Message); // } // } // this.ImageFilePathes.Add(newImageFilePath); // // if (lastImageFilePath != null) // { // if (lastImageFilePath.imageMd5 == newImageFilePath.imageMd5 && File.Exists(filePath)) // continue; // lastImageFilePath.imageMd5 = newImageFilePath.imageMd5; // } // else // this.LastImageFilePathes.Add(newImageFilePath); if (PsdLayerToNGUI.verbose) { Debug.Log("Saving '" + newImageFilePath.filePath + "'"); } var data = layer.psdLayer.mergeChannels(); if (data == null) { continue; } Texture tex = null; if (pa.sliceArea != null) { tex = MakeSlicedSprites(ref data, layer, pa.sliceArea); } else { tex = MakeTexture(ref data, layer); } if (tex != null) { if (!System.IO.Directory.Exists(prePath)) { System.IO.Directory.CreateDirectory(prePath); } System.IO.File.WriteAllBytes(filePath, data); AssetDatabase.ImportAsset(filePath, ImportAssetOptions.Default); Texture2D.DestroyImmediate(tex); } } }
private async Task <bool> ExecuteWithTimeout(AsyncCodeActivityContext context, CancellationToken cancellationToken = default) { var imageFilePath = ImageFilePath.Get(context); return(await Task.FromResult(new Models.WallpaperChanger().SetWallPaper(imageFilePath))); }
private void SaveLayersToPNGs_imple(string prePath, List <Layer> layers) { string[] tempData = prePath.Split('/'); var name = this.PsdFileName.Split('.')[0]; prePath = "Assets/Resources/Images/" + name + "/" + tempData[tempData.Length - 1]; Debug.Log(prePath); var psdFileStream = new FileStream(this.PsdFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); foreach (var layer in layers) { if (!layer.canLoadLayer) { continue; } if (layer.isContainer) { this.SaveLayersToPNGs_imple(prePath + "/" + layer.name, layer.children); continue; } var pa = new PsdLayerCommandParser.ControlParser(prePath, layer); if (pa.type == PsdLayerCommandParser.ControlType.Script || pa.type == PsdLayerCommandParser.ControlType.Label || pa.type == PsdLayerCommandParser.ControlType.LabelButton) { continue; } var fileName = pa.fullName; if (this.HasUnacceptibleChar(fileName)) { Debug.LogError(fileName + " Contains wrong character '\\ / : * ? \" < > |' not allowed"); continue; } var filePath = prePath + "/" + fileName + ".png"; ImageFilePath newImageFilePath = null; { try { psdFileStream.Position = 0; var br = new BinaryReader(psdFileStream); { layer.LoadData(br, this.Psd.headerInfo.bpp); newImageFilePath = new ImageFilePath(filePath, "pass"); } } catch (System.Exception e) { Debug.LogError(e.Message); } } this.ImageFilePathes.Add(newImageFilePath); var data = layer.psdLayer.mergeChannels(); if (data == null) { continue; } Texture tex = null; if (pa.sliceArea != null) { tex = MakeSlicedSprites(ref data, layer, pa.sliceArea); } else { tex = MakeTexture(ref data, layer); } if (tex != null) { if (!System.IO.Directory.Exists(prePath)) { System.IO.Directory.CreateDirectory(prePath); } System.IO.File.WriteAllBytes(filePath, data); AssetDatabase.Refresh(); TextureImporter importer = AssetImporter.GetAtPath(filePath) as TextureImporter; importer.maxTextureSize = 4096; importer.spriteImportMode = SpriteImportMode.Single; importer.textureType = TextureImporterType.Sprite; AssetDatabase.ImportAsset(filePath, ImportAssetOptions.ForceUpdate); dims.Add(new Vector4(pa.area.left, pa.area.top, pa.area.width, pa.area.height)); Debug.Log(dims[dims.Count - 1]); Texture2D.DestroyImmediate(tex); } } psdFileStream.Close(); }
private void SaveLayersToPNGs_imple(string prePath, List<Layer> layers) { var psdFileStream = new FileStream(this.PsdFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); foreach (var layer in layers) { if (!layer.canLoadLayer) continue; if (layer.isContainer) { this.SaveLayersToPNGs_imple(prePath + "/" + layer.name, layer.children); continue; } var pa = new PsdLayerCommandParser.ControlParser(prePath, layer); if (pa.type == PsdLayerCommandParser.ControlType.Script || pa.type == PsdLayerCommandParser.ControlType.Label || pa.type == PsdLayerCommandParser.ControlType.LabelButton) continue; var fileName = pa.fullName; if (this.HasUnacceptibleChar(fileName)) { Debug.LogError(fileName + " Contains wrong character '\\ / : * ? \" < > |' not allowed"); continue; } var filePath = prePath + "/" + fileName + ".png"; ImageFilePath newImageFilePath = null; { try { psdFileStream.Position = 0; var br = new BinaryReader(psdFileStream); { layer.LoadData(br, this.Psd.headerInfo.bpp); newImageFilePath = new ImageFilePath(filePath, "pass"); } } catch (System.Exception e) { Debug.LogError(e.Message); } } this.ImageFilePathes.Add(newImageFilePath); //**md5: too slow // ImageFilePath lastImageFilePath = null; // ImageFilePath newImageFilePath = null; // { // try // { // if (this.LastImageFilePathes != null && this.LastImageFilePathes.Count > 0) // { // lastImageFilePath = this.LastImageFilePathes.Find(t=>t.filePath == filePath); // } // // psdFileStream.Position = 0; // var br = new BinaryReader(psdFileStream); // { // layer.LoadData(br, this.Psd.headerInfo.bpp); // var imageMd5 = this.CalcMd5Imple(br.BaseStream); // var imageMd5 = "pass"; // newImageFilePath = new ImageFilePath(filePath, imageMd5); // } // } // catch (System.Exception e) // { // Debug.LogError(e.Message); // } // } // this.ImageFilePathes.Add(newImageFilePath); // // if (lastImageFilePath != null) // { // if (lastImageFilePath.imageMd5 == newImageFilePath.imageMd5 && File.Exists(filePath)) // continue; // lastImageFilePath.imageMd5 = newImageFilePath.imageMd5; // } // else // this.LastImageFilePathes.Add(newImageFilePath); if (PsdLayerToNGUI.verbose) Debug.Log("Saving '" + newImageFilePath.filePath + "'"); var data = layer.psdLayer.mergeChannels(); if (data == null) continue; Texture tex = null; if (pa.sliceArea != null) { tex = MakeSlicedSprites(ref data, layer, pa.sliceArea); } else { tex = MakeTexture(ref data, layer); } if (tex != null) { if (!System.IO.Directory.Exists(prePath)) System.IO.Directory.CreateDirectory(prePath); System.IO.File.WriteAllBytes(filePath, data); AssetDatabase.ImportAsset(filePath, ImportAssetOptions.Default); Texture2D.DestroyImmediate(tex); } } }