/// <summary> /// /// </summary> /// <param name="fileName"></param> public static void Delete(string fileName) { if (Exists(fileName)) { File.Delete(fileName); } }
/// <summary> /// Deletes the specified file. /// </summary> /// <param name="_filePath">The name of the file to be deleted.</param> public static void Delete(string _filePath) { #if (UNITY_WEBPLAYER || UNITY_WEBGL) Debug.LogError("[CPFileOperations] File operations are not supported."); #else File.Delete(_filePath); #endif }
public bool DeleteSave() { if (!File.Exists(_saveFilePath)) { return(false); } File.Delete(_saveFilePath); return(!File.Exists(_saveFilePath)); }
private void GenerateAtlasSpritePrefab(string atlasDir) { Dictionary <string, string> md5Map = new Dictionary <string, string>(); FileInfo[] resFiles = BMEditUtility.GetAllFiles(atlasDir, "*.*"); for (int j = 0; j < resFiles.Length; j++) { FileInfo info = resFiles[j]; if (info.FullName.EndsWith(".meta", StringComparison.Ordinal) || info.FullName.EndsWith(".txt", StringComparison.Ordinal)) { continue; } string dirName = Path.GetFileName(info.DirectoryName); string outPath = $"{_settings.atlasSpritePrefabDir}{dirName}/"; string spriteFileName = Path.GetFileName(info.FullName); string spriteName = Path.GetFileNameWithoutExtension(info.FullName); string texPath = BMEditUtility.Absolute2Relativity(info.FullName); string md5 = HashHelper.ComputeMD5(texPath); md5Map.Add(texPath, md5); TextureImporter ti = AssetImporter.GetAtPath(texPath) as TextureImporter; if (ti) { if (!Directory.Exists(outPath)) { Directory.CreateDirectory(outPath); } GameObject spritePrefab = new GameObject(spriteName); SpriteRenderer spriteRenderer = spritePrefab.AddComponent <SpriteRenderer>(); Vector4 border = ti.spriteBorder; ti.spritePackingTag = "Atlas_" + dirName; ti.SaveAndReimport(); spriteRenderer.sprite = AssetDatabase.LoadAssetAtPath <Sprite>(texPath);; //spritePrefab.hideFlags = HideFlags.HideInHierarchy; var savePath = outPath + spriteName + ".prefab"; if (File.Exists(savePath)) { File.Delete(savePath); } PrefabUtility.SaveAsPrefabAsset(spritePrefab, savePath); //var texture2D = AssetDatabase.LoadAssetAtPath<Texture2D>(rPath); //var sprite = Sprite.Create(texture2D, new Rect(0,0,texture2D.width,texture2D.height), new Vector2(0.5f,0.5f), 400, 0,SpriteMeshType.FullRect,border); DestroyImmediate(spritePrefab); } } //Save md5 BMEditUtility.SaveDictionary(Path.Combine(atlasDir, "manifest.txt"), md5Map); }
/// <summary> /// Renames a file /// </summary> /// <param name="_filePath">The file to rename.</param> /// <param name="_newFileName">New file name for this file.</param> public static void Rename(string _filePath, string _newFileName) { #if (UNITY_WEBPLAYER || UNITY_WEBGL) Debug.LogError("[CPFileOperations] File operations are not supported."); #elif UNITY_WINRT Debug.LogError("[CPFileOperations] Rename Unimplemeted on windows"); #else string _fileName = Path.GetFileName(_filePath); string _newFilePath = _filePath.Replace(_fileName, _newFileName); if (File.Exists(_filePath)) { if (File.Exists(_newFilePath)) { File.Delete(_newFilePath); //Just deleting a head incase if exists. } File.Move(_filePath, _newFilePath); } #endif }
private void SetAdapterUpdateInfo(string nameDep, string currentVersion, string latestVersion, string internalContent, string latestContent) { using (new EditorGUILayout.VerticalScope(AppodealDependencyUtils.BoxStyle)) { using (new EditorGUILayout.HorizontalScope(GUILayout.Height(20))) { GUILayout.Space(2); if (string.IsNullOrEmpty(nameDep) || string.IsNullOrEmpty(currentVersion) || string.IsNullOrEmpty(latestVersion)) { return; } GUILayout.Button(nameDep, packageInfoStyle, GUILayout.Width(145)); GUILayout.Space(56); GUILayout.Button( AppodealDependencyUtils.ReplaceBetaVersion(currentVersion), packageInfoStyle, GUILayout.Width(110)); GUILayout.Space(85); GUILayout.Button( AppodealDependencyUtils.ReplaceBetaVersion(latestVersion), packageInfoStyle); GUILayout.Space(15); if (GUILayout.Button( new GUIContent { text = AppodealDependencyUtils.ActionRemove }, btnFieldWidth)) { var path = $"{AppodealDependencyUtils.Network_configs_path}{nameDep}Dependencies.xml"; AppodealDependencyUtils.ReplaceInFile(path, internalContent, ""); var text = System.IO.File.ReadAllLines(path).Where(s => s.Trim() != string.Empty).ToArray(); File.Delete(path); System.IO.File.WriteAllLines(path, text); AppodealDependencyUtils.FormatXml(System.IO.File.ReadAllText(path)); UpdateWindow(); } var current = AppodealDependencyUtils.GetMajorVersion( AppodealDependencyUtils.ReplaceBetaVersion(currentVersion)); var last = AppodealDependencyUtils.GetMajorVersion( AppodealDependencyUtils.ReplaceBetaVersion(latestVersion)); if (AppodealDependencyUtils.CompareVersion(current, last) < 0) { CompareForAction(0, nameDep, internalContent, latestContent); } else { CompareForAction(AppodealDependencyUtils.CompareVersion( AppodealDependencyUtils.ReplaceBetaVersion(currentVersion), AppodealDependencyUtils.ReplaceBetaVersion(latestVersion)), nameDep, internalContent, latestContent); } } } }