Elin Decompiled Documentation EA 23.264 Nightly
Loading...
Searching...
No Matches
GalleryFlattenAndRename Class Reference

Static Public Member Functions

static UD_Int_String Run ()
 

Static Public Attributes

static string root = CorePath.CorePackage.ETC + "/Gallery"
 
static UD_Int_String dict
 
const int ThumbMaxW = 360
 
const int ThumbMaxH = 240
 

Static Private Member Functions

static void MoveAllFilesUnderSubfoldersToRoot (string root)
 
static void RenameAllFilesToLeadingNumber (string root)
 
static void CreateThumbnailsSameFolder (string root, int maxW, int maxH)
 
static bool IsImageExt (string ext)
 
static Texture2D ResizeTo (Texture2D src, int w, int h)
 

Detailed Description

Definition at line 5 of file GalleryFlattenAndRename.cs.

Member Function Documentation

◆ CreateThumbnailsSameFolder()

static void GalleryFlattenAndRename.CreateThumbnailsSameFolder ( string  root,
int  maxW,
int  maxH 
)
inlinestaticprivate

Definition at line 82 of file GalleryFlattenAndRename.cs.

83 {
84 string[] files = Directory.GetFiles(root, "*", SearchOption.TopDirectoryOnly);
85 foreach (string text in files)
86 {
87 if (text.EndsWith(".meta"))
88 {
89 continue;
90 }
91 string path = text + "_t";
92 if (File.Exists(path))
93 {
94 continue;
95 }
96 string text2 = Path.GetExtension(text).ToLowerInvariant();
97 if (!IsImageExt(text2) || Path.GetFileName(text).Contains(text2 + "_t"))
98 {
99 continue;
100 }
101 byte[] data = File.ReadAllBytes(text);
102 Texture2D texture2D = new Texture2D(2, 2, TextureFormat.RGBA32, mipChain: false, linear: false);
103 if (!texture2D.LoadImage(data))
104 {
105 Object.DestroyImmediate(texture2D);
106 continue;
107 }
108 int width = texture2D.width;
109 int height = texture2D.height;
110 float num = Mathf.Min((float)maxW / (float)width, (float)maxH / (float)height);
111 if (num > 1f)
112 {
113 num = 1f;
114 }
115 int w = Mathf.Max(1, Mathf.RoundToInt((float)width * num));
116 int h = Mathf.Max(1, Mathf.RoundToInt((float)height * num));
117 Texture2D texture2D2 = ResizeTo(texture2D, w, h);
118 byte[] bytes = ((!(text2 == ".png")) ? texture2D2.EncodeToJPG(90) : texture2D2.EncodeToPNG());
119 File.WriteAllBytes(path, bytes);
120 Object.DestroyImmediate(texture2D);
121 Object.DestroyImmediate(texture2D2);
122 }
123 }
static Texture2D ResizeTo(Texture2D src, int w, int h)
static bool IsImageExt(string ext)

References IsImageExt(), ResizeTo(), and root.

Referenced by Run().

◆ IsImageExt()

static bool GalleryFlattenAndRename.IsImageExt ( string  ext)
inlinestaticprivate

Definition at line 125 of file GalleryFlattenAndRename.cs.

126 {
127 if (!(ext == ".png") && !(ext == ".jpg"))
128 {
129 return ext == ".jpeg";
130 }
131 return true;
132 }

Referenced by CreateThumbnailsSameFolder(), and RenameAllFilesToLeadingNumber().

◆ MoveAllFilesUnderSubfoldersToRoot()

static void GalleryFlattenAndRename.MoveAllFilesUnderSubfoldersToRoot ( string  root)
inlinestaticprivate

Definition at line 46 of file GalleryFlattenAndRename.cs.

47 {
48 string[] directories = Directory.GetDirectories(root, "*", SearchOption.AllDirectories);
49 for (int i = 0; i < directories.Length; i++)
50 {
51 string[] files = Directory.GetFiles(directories[i], "*", SearchOption.TopDirectoryOnly);
52 foreach (string text in files)
53 {
54 string text2 = Path.Combine(root, Path.GetFileName(text));
55 if (!File.Exists(text2))
56 {
57 File.Move(text, text2);
58 }
59 }
60 }
61 }

References root.

Referenced by Run().

◆ RenameAllFilesToLeadingNumber()

static void GalleryFlattenAndRename.RenameAllFilesToLeadingNumber ( string  root)
inlinestaticprivate

Definition at line 63 of file GalleryFlattenAndRename.cs.

64 {
65 string[] files = Directory.GetFiles(root, "*", SearchOption.TopDirectoryOnly);
66 foreach (string text in files)
67 {
68 string extension = Path.GetExtension(text);
69 if (IsImageExt(extension))
70 {
71 string text2 = Path.GetFileNameWithoutExtension(text).Split('_')[0];
72 string text3 = Path.Combine(root, text2 + extension);
73 if (text != text3)
74 {
75 File.Move(text, text3);
76 }
77 dict[text2.ToInt()] = text2 + extension;
78 }
79 }
80 }

References dict, IsImageExt(), and root.

Referenced by Run().

◆ ResizeTo()

static Texture2D GalleryFlattenAndRename.ResizeTo ( Texture2D  src,
int  w,
int  h 
)
inlinestaticprivate

Definition at line 134 of file GalleryFlattenAndRename.cs.

135 {
136 RenderTexture temporary = RenderTexture.GetTemporary(w, h, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
137 RenderTexture active = RenderTexture.active;
138 Graphics.Blit(src, temporary);
139 RenderTexture.active = temporary;
140 Texture2D texture2D = new Texture2D(w, h, TextureFormat.RGBA32, mipChain: false, linear: false);
141 texture2D.ReadPixels(new Rect(0f, 0f, w, h), 0, 0);
142 texture2D.Apply(updateMipmaps: false, makeNoLongerReadable: false);
143 RenderTexture.active = active;
144 RenderTexture.ReleaseTemporary(temporary);
145 return texture2D;
146 }

Referenced by CreateThumbnailsSameFolder().

◆ Run()

static UD_Int_String GalleryFlattenAndRename.Run ( )
inlinestatic

Definition at line 15 of file GalleryFlattenAndRename.cs.

16 {
17 dict = new UD_Int_String();
19 string[] array = Directory.GetDirectories(root, "*", SearchOption.AllDirectories).ToArray();
20 for (int i = 0; i < array.Length; i++)
21 {
22 Directory.Delete(array[i], recursive: true);
23 }
24 array = Directory.GetFiles(root, "*", SearchOption.TopDirectoryOnly);
25 foreach (string text in array)
26 {
27 if (text.EndsWith("meta"))
28 {
29 File.Delete(text);
30 }
31 }
33 array = Directory.GetFiles(root, "*", SearchOption.TopDirectoryOnly);
34 foreach (string text2 in array)
35 {
36 if (text2.EndsWith("meta"))
37 {
38 File.Delete(text2);
39 }
40 }
42 Debug.Log("[Gallery] Done. Total:" + dict.Count);
43 return dict;
44 }
static void MoveAllFilesUnderSubfoldersToRoot(string root)
static void CreateThumbnailsSameFolder(string root, int maxW, int maxH)
static void RenameAllFilesToLeadingNumber(string root)

References UDictionary< TKey, TValue >.Count, CreateThumbnailsSameFolder(), Debug, dict, MoveAllFilesUnderSubfoldersToRoot(), RenameAllFilesToLeadingNumber(), and root.

Referenced by CoreRef.RebuildSketchList().

Member Data Documentation

◆ dict

UD_Int_String GalleryFlattenAndRename.dict
static

Definition at line 9 of file GalleryFlattenAndRename.cs.

Referenced by RenameAllFilesToLeadingNumber(), and Run().

◆ root

string GalleryFlattenAndRename.root = CorePath.CorePackage.ETC + "/Gallery"
static

◆ ThumbMaxH

const int GalleryFlattenAndRename.ThumbMaxH = 240
static

Definition at line 13 of file GalleryFlattenAndRename.cs.

◆ ThumbMaxW

const int GalleryFlattenAndRename.ThumbMaxW = 360
static

Definition at line 11 of file GalleryFlattenAndRename.cs.


The documentation for this class was generated from the following file: