7 public static string root = CorePath.CorePackage.ETC +
"/Gallery";
19 string[] array = Directory.GetDirectories(
root,
"*", SearchOption.AllDirectories).ToArray();
20 for (
int i = 0; i < array.Length; i++)
22 Directory.Delete(array[i], recursive:
true);
24 array = Directory.GetFiles(
root,
"*", SearchOption.TopDirectoryOnly);
25 foreach (
string text
in array)
27 if (text.EndsWith(
"meta"))
33 array = Directory.GetFiles(
root,
"*", SearchOption.TopDirectoryOnly);
34 foreach (
string text2
in array)
36 if (text2.EndsWith(
"meta"))
48 string[] directories = Directory.GetDirectories(
root,
"*", SearchOption.AllDirectories);
49 for (
int i = 0; i < directories.Length; i++)
51 string[] files = Directory.GetFiles(directories[i],
"*", SearchOption.TopDirectoryOnly);
52 foreach (
string text
in files)
54 string text2 = Path.Combine(
root, Path.GetFileName(text));
55 if (!File.Exists(text2))
57 File.Move(text, text2);
65 string[] files = Directory.GetFiles(
root,
"*", SearchOption.TopDirectoryOnly);
66 foreach (
string text
in files)
68 string extension = Path.GetExtension(text);
71 string text2 = Path.GetFileNameWithoutExtension(text).Split(
'_')[0];
72 string text3 = Path.Combine(
root, text2 + extension);
75 File.Move(text, text3);
77 dict[text2.ToInt()] = text2 + extension;
84 string[] files = Directory.GetFiles(
root,
"*", SearchOption.TopDirectoryOnly);
85 foreach (
string text
in files)
87 if (text.EndsWith(
".meta"))
91 string path = text +
"_t";
92 if (File.Exists(path))
96 string text2 = Path.GetExtension(text).ToLowerInvariant();
97 if (!
IsImageExt(text2) || Path.GetFileName(text).Contains(text2 +
"_t"))
101 byte[] data = File.ReadAllBytes(text);
102 Texture2D texture2D =
new Texture2D(2, 2, TextureFormat.RGBA32, mipChain:
false, linear:
false);
103 if (!texture2D.LoadImage(data))
105 Object.DestroyImmediate(texture2D);
108 int width = texture2D.width;
109 int height = texture2D.height;
110 float num = Mathf.Min((
float)maxW / (
float)width, (
float)maxH / (
float)height);
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);
127 if (!(ext ==
".png") && !(ext ==
".jpg"))
129 return ext ==
".jpeg";
134 private static Texture2D
ResizeTo(Texture2D src,
int w,
int h)
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);
static Texture2D ResizeTo(Texture2D src, int w, int h)
static UD_Int_String Run()
static void MoveAllFilesUnderSubfoldersToRoot(string root)
static UD_Int_String dict
static void CreateThumbnailsSameFolder(string root, int maxW, int maxH)
static bool IsImageExt(string ext)
static void RenameAllFilesToLeadingNumber(string root)