private void UpdateDependency(string nameDependency, string previous, string latest)
        {
            var path = AppodealDependencyUtils.Network_configs_path + nameDependency +
                       AppodealDependencyUtils.Dependencies + ".xml";

            if (!File.Exists(path))
            {
                AppodealDependencyUtils.ShowInternalErrorDialog(this,
                                                                "Can't find config with path " + path, $"path - {nameDependency}");
            }
            else
            {
                string contentString;
                using (var reader = new StreamReader(path))
                {
                    contentString = reader.ReadToEnd();
                    reader.Close();
                }

                contentString = Regex.Replace(contentString, previous, latest);

                using (var writer = new StreamWriter(path))
                {
                    writer.Write(contentString);
                    writer.Close();
                }
            }
        }
Esempio n. 2
0
        public static string GetCachedPath(CardData data)
        {
            var url = data.Image;

            if (string.IsNullOrEmpty(data.Title))
            {
                data.Title = "default";
            }

            string imageName = string.Format(cachedImageNameFormat, data.Title, data.Id);
            string fileName  = Application.persistentDataPath + "/" + Path.GetFileName(imageName);

#if !UNITY_WINRT
            if (File.Exists(fileName))
            {
                url = "file://" + fileName;
            }
            else
#endif
            {
                url = AzureMuseumImageFormatter.GetImageUri(url, 277, 274).ToString();
            }

            return(url);
        }
Esempio n. 3
0
        private void ImportConfig(string nameDep, string content)
        {
            var path = AppodealDependencyUtils.Network_configs_path + nameDep + AppodealDependencyUtils.Dependencies +
                       AppodealDependencyUtils.XmlFileExtension;

            if (File.Exists(path))
            {
                UpdateDependency(nameDep, AppodealDependencyUtils.SpecCloseDependencies,
                                 content + "\n" + AppodealDependencyUtils.SpecCloseDependencies);
                AppodealDependencyUtils.FormatXml(System.IO.File.ReadAllText(path));
            }
            else
            {
                using (TextWriter writer = new StreamWriter(path, false))
                {
                    writer.WriteLine(AppodealDependencyUtils.SpecOpenDependencies
                                     + content + "\n" + AppodealDependencyUtils.SpecCloseDependencies);
                    writer.Close();
                }

                AppodealDependencyUtils.FormatXml(System.IO.File.ReadAllText(path));
            }

            UpdateWindow();
        }
Esempio n. 4
0
 public void LoadSave()
 {
     if (File.Exists(_saveFilePath))
     {
         var saveToLoad = JsonConvert.DeserializeObject <Save>(File.ReadAllText(_saveFilePath));
         LoadSaveGameObject(saveToLoad);
     }
 }
Esempio n. 5
0
        private void LoadFileChangeLog()
        {
            var filePath = Path.Combine(Application.dataPath, fileName);

            if (File.Exists(filePath))
            {
                _changeLoggerStr = JsonFile.LoadJsonFile <string>(filePath);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Determines whether the specified file exists.
        /// </summary>
        /// <returns><c>true</c>, if file exists at given path, <c>false</c> otherwise.</returns>
        /// <param name="_filePath">The file to check.</param>
        public static bool Exists(string _filePath)
        {
#if (UNITY_WEBPLAYER || UNITY_WEBGL)
            Debug.LogError("[CPFileOperations] File operations are not supported.");
            return(false);
#else
            return(File.Exists(_filePath));
#endif
        }
 private void EnsurePluginSelected()
 {
     if (!File.Exists(_config.IlWeaverPluginExecutablePath))
     {
         EditorUtility.DisplayDialog("Error",
                                     $"Unable to find plugin, please make sure that '{PluginExecutablePathLabel}' is correct.", "Pick file");
         SelectPluginViaPicker();
     }
 }
Esempio n. 8
0
        public bool DeleteSave()
        {
            if (!File.Exists(_saveFilePath))
            {
                return(false);
            }

            File.Delete(_saveFilePath);

            return(!File.Exists(_saveFilePath));
        }
        public static void ExecuteAction(IPDFDeviceActionHandler actionHandler, IPDFDevice device, PDFAction action)
        {
            if (action != null)
            {
                PDFAction.ActionType type = action.GetActionType();

                switch (type)
                {
                case PDFAction.ActionType.Unsupported:
                    break;

                case PDFAction.ActionType.GoTo:
                    PDFDest dest = action.GetDest();
                    actionHandler.HandleGotoAction(device, dest.PageIndex);
                    break;

                case PDFAction.ActionType.RemoteGoTo:
                    string resolvedFilePath = actionHandler.HandleRemoteGotoActionPathResolving(device,
                                                                                                action.GetFilePath());

#if !((UNITY_4_6 || UNITY_4_7))
                    if (File.Exists(resolvedFilePath))
                    {
                        string password = actionHandler.HandleRemoteGotoActionPasswordResolving(device,
                                                                                                resolvedFilePath);
                        PDFDocument newDocument = new PDFDocument(resolvedFilePath, password);

                        if (newDocument.IsValid)
                        {
                            actionHandler.HandleRemoteGotoActionResolved(device, newDocument,
                                                                         action.GetDest().PageIndex);
                        }
                        else
                        {
                            actionHandler.HandleRemoteGotoActionUnresolved(device, resolvedFilePath);
                        }
                    }
                    else
#endif
                    actionHandler.HandleRemoteGotoActionUnresolved(device, resolvedFilePath);


                    break;

                case PDFAction.ActionType.Uri:
                    actionHandler.HandleUriAction(device, action.GetURIPath());
                    break;

                case PDFAction.ActionType.Launch:
                    actionHandler.HandleLaunchAction(device, action.GetFilePath());
                    break;
                }
            }
        }
Esempio n. 10
0
        /// <summary>
        /// </summary>
        /// <param name="file_path"></param>
        /// <returns></returns>
        public static Texture2D LoadPng(string file_path)
        {
            Texture2D tex = null;

            if (File.Exists(file_path))
            {
                var file_data = File.ReadAllBytes(file_path);
                tex = new Texture2D(2, 2);
                tex.LoadImage(file_data); //..this will auto-resize the texture dimensions.
            }

            return(tex);
        }
Esempio n. 11
0
        public static IEnumerator Cache(CardData data)
        {
            var url = data.Image;

            if (string.IsNullOrEmpty(data.Title))
            {
                data.Title = "default";
            }

            bool   saveToFile;
            string imageName = string.Format(cachedImageNameFormat, data.Title, data.Id);
            string fileName  = Application.persistentDataPath + "/" + Path.GetFileName(imageName);

#if !UNITY_WINRT
            if (File.Exists(fileName))
            {
                saveToFile = false;
                url        = "file://" + fileName;
            }
            else
#endif
            {
                saveToFile = true;
                url        = AzureMuseumImageFormatter.GetImageUri(url, 277, 274).ToString();
            }

            WWW www = null;

            int tries = 3;
            while (--tries >= 0)
            {
                www = new WWW(url);

                yield return(www);

                if (www.bytesDownloaded != 0)
                {
                    break;
                }
            }

#if !UNITY_WINRT
            if (saveToFile && www != null && www.bytesDownloaded != 0)
            {
                fileName = Application.persistentDataPath + "/" + Path.GetFileName(imageName);
                var cache = new FileStream(fileName, FileMode.Create);
                cache.Write(www.bytes, 0, www.bytes.Length);
                cache.Close();
            }
#endif
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        public static IEnumerator CacheAndSet(SpriteRenderer renderer, CardData data)
        {
            var url = data.Image;

            if (string.IsNullOrEmpty(data.Title))
            {
                data.Title = "default";
            }

            bool   saveToFile;
            string imageName = string.Format(cachedImageNameFormat, data.Title, data.Id);
            string fileName  = Application.persistentDataPath + "/" + Path.GetFileName(imageName);

            if (File.Exists(fileName))
            {
                saveToFile = false;
                url        = "file://" + fileName;
            }
            else
            {
                saveToFile = true;
                url        = AzureMuseumImageFormatter.GetImageUri(url, 277, 274).ToString();
            }

            var www = new WWW(url);

            yield return(www);

            if (saveToFile)
            {
                fileName = Application.persistentDataPath + "/" + Path.GetFileName(imageName);
                File.WriteAllBytes(fileName, www.bytes);
            }

            if (renderer != null)
            {
                var sprite = Sprite.Create(
                    www.texture,
                    new Rect(0, 0, 277, 274),
                    new Vector2(0.5f, 0.5f));

                renderer.sprite = sprite;
            }
        }
Esempio n. 14
0
        /// <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
        }
Esempio n. 15
0
        private IEnumerator GetAppodealSDKData()
        {
            yield return(null);

            #region Internal

            if (AppodealDependencyUtils.GetInternalDependencyPath() != null)
            {
                foreach (var fileInfo in AppodealDependencyUtils.GetInternalDependencyPath())
                {
                    if (!File.Exists(AppodealDependencyUtils.Network_configs_path + fileInfo.Name))
                    {
                        AppodealDependencyUtils.ShowInternalErrorDialog(this,
                                                                        $"File doesn't exist - {AppodealDependencyUtils.Network_configs_path + fileInfo.Name}",
                                                                        string.Empty);
                    }
                    else
                    {
                        GetInternalDependencies(AppodealDependencyUtils.Network_configs_path + fileInfo.Name);
                    }
                }
            }
            else
            {
                AppodealDependencyUtils.ShowInternalErrorDialog(this,
                                                                "Can't find internal dependencies.", string.Empty);
            }

            #endregion

            #region Plugin

            var requestPlugin = UnityWebRequest.Get(AppodealDependencyUtils.PluginRequest);
            yield return(requestPlugin.Send());

            if (requestPlugin.isError)
            {
                Debug.LogError(requestPlugin.error);
                AppodealDependencyUtils.ShowInternalErrorDialog(this, requestPlugin.error, string.Empty);
            }
            else
            {
                if (string.IsNullOrEmpty(requestPlugin.downloadHandler.text))
                {
                    yield break;
                }

                if (AppodealAds.Unity.Api.Appodeal.APPODEAL_PLUGIN_VERSION.Contains("-Beta"))
                {
                    appodealUnityPlugin = JsonHelper.FromJson <AppodealUnityPlugin>(JsonHelper.fixJson(requestPlugin.downloadHandler.text))
                                          .ToList().FirstOrDefault(x => x.build_type.Equals("beta"));
                }
                else
                {
                    appodealUnityPlugin = JsonHelper.FromJson <AppodealUnityPlugin>(JsonHelper.fixJson(requestPlugin.downloadHandler.text))
                                          .ToList().FirstOrDefault(x => x.build_type.Equals("stable"));
                }
            }

            #endregion

            #region Adapters

            var requestAdapters = UnityWebRequest.Get(AppodealDependencyUtils.AdaptersRequest +
                                                      AppodealDependencyUtils.ReplaceBetaVersion(AppodealAds.Unity.Api
                                                                                                 .Appodeal.APPODEAL_PLUGIN_VERSION));

            yield return(requestAdapters.Send());

            if (requestAdapters.isError)
            {
                Debug.LogError(requestAdapters.error);
                AppodealDependencyUtils.ShowInternalErrorDialog(this, requestAdapters.error, string.Empty);
            }
            else
            {
                if (string.IsNullOrEmpty(requestAdapters.downloadHandler.text))
                {
                    yield break;
                }
                if (requestAdapters.downloadHandler.text.Contains("error"))
                {
                    AppodealDependencyUtils.ShowInternalErrorDialog(this,
                                                                    $"Can't find network configs by {AppodealAds.Unity.Api.Appodeal.APPODEAL_PLUGIN_VERSION} version",
                                                                    string.Empty);
                    yield break;
                }
                var networkDependencies = JsonHelper.FromJson <NetworkDependency>(
                    JsonHelper.fixJson(requestAdapters.downloadHandler.text));

                if (networkDependencies.Length > 0)
                {
                    foreach (var networkDependency in networkDependencies)
                    {
                        if (!string.IsNullOrEmpty(networkDependency.name) &&
                            !networkDependency.name.Equals(AppodealDependencyUtils.TwitterMoPub))
                        {
                            latestDependencies.Add(networkDependency.name, networkDependency);
                        }
                    }
                }
            }

            #endregion

            coroutine = null;

            isPluginInfoReady = true;
        }
Esempio n. 16
0
 public bool SaveExists()
 {
     return(File.Exists(_saveFilePath));
 }
Esempio n. 17
0
 /// <summary>
 /// Check if the file exists
 /// </summary>
 /// <param name="path">Path of the file</param>
 /// <returns>bool</returns>
 public static bool Exists(string path)
 {
     return(File.Exists(path));
 }
Esempio n. 18
0
 /// <summary>
 /// 路径是否存在
 /// </summary>
 /// <param name="fileName"></param>
 /// <returns></returns>
 public static bool Exists(string fileName)
 {
     return(File.Exists(fileName));
 }