예제 #1
0
    public static void CopyFile(string sourceFile, string targetFile)
    {
#if ENABLE_BUILD_LOG
        Debug.Log(sourceFile + " " + targetFile);
#endif
        // Convert to full path
        sourceFile = Path.GetFullPath(sourceFile);
        targetFile = Path.GetFullPath(targetFile);

        if (Directory.Exists(sourceFile))
        {
            // Copy directory
            DirectoryCopy(sourceFile, targetFile, true);
        }
        else
        {
            // Copy file
            // Create target path if it doesn't exist
            string targetPath = Path.GetDirectoryName(targetFile);
            if (PathUtility.CreateDirectory(targetPath) == false)
            {
                Debug.LogError("Create target path failed : " + targetPath);
                return;
            }

            // Notice can not use AssetDatabase.DeleteAsset, AssetDatabase.CopyAsset
            // 1. DeleteAsset will cause GUID changed which is used in ezgui
            // 2. CopyAsset will cause a internal asset of unity.
            File.Delete(targetFile);
            File.Copy(sourceFile, targetFile);
        }
    }
예제 #2
0
        public int Execute(ICommandOption opt)
        {
            var option = (CommandOption)opt;

            var translator = new KeySwitchListListToJsonModelList {
                Formatted = true
            };
            var interactor = new ExportingTemplateJsonInteractor(translator);

            var response = interactor.Execute();

            if (StringHelper.IsNullOrTrimEmpty(option.OutputPath))
            {
                Console.Out.WriteLine(response.Text);
            }
            else
            {
                var outputDirectory = Path.GetDirectoryName(option.OutputPath) !;
                PathUtility.CreateDirectory(outputDirectory);

                Console.WriteLine($"generating json to {option.OutputPath}");
                File.WriteAllText(option.OutputPath, response.Text);
            }

            return(0);
        }
        public int Execute(ICommandOption opt)
        {
            var option = (CommandOption)opt;

            using var repository = new LiteDbKeySwitchRepository(option.DatabasePath);
            var translator = new KeySwitchToStudioOneKeySwitchModel();
            var presenter  = new IExportingStudioOneKeySwitchPresenter.Null();
            var interactor = new ExportingStudioOneKeySwitchInteractor(repository, translator, presenter);

            var input = new ExportingStudioOneKeySwitchRequest(option.Developer, option.Product, option.Instrument);

            Console.WriteLine($"Developer=\"{option.Developer}\", Product=\"{option.Product}\", Instrument=\"{option.Instrument}\"");

            var response = interactor.Execute(input);

            if (!response.Elements.Any())
            {
                Console.WriteLine("records not found");
                return(0);
            }

            foreach (var i in response.Elements)
            {
                var outputDirectory = option.OutputDirectory;

                if (option.DirectoryStructure)
                {
                    outputDirectory = EntityDirectoryHelper.CreateDirectoryTree(
                        i.KeySwitch,
                        new DirectoryPath(option.OutputDirectory)
                        ).Path;
                }
                else
                {
                    PathUtility.CreateDirectory(outputDirectory);
                }

                var prefix = $"{i.KeySwitch.ProductName} {i.KeySwitch.InstrumentName}";
                var path   = $"{prefix}.keyswitch";
                path = PathUtility.GenerateFilePathWhenExist(path, outputDirectory, option.OverWrite);

                Console.Out.WriteLine($"export to {path}");
                File.WriteAllText(path, i.XmlText.Value, Encoding.UTF8);
            }

            return(0);
        }
예제 #4
0
 static void CreateAssetDirectory()
 {
     // メソッド内部でフォルダの有無を確認している
     PathUtility.CreateDirectory(DirectoryPath.resources);
     PathUtility.CreateDirectory(audioFolder);
 }
예제 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="subPath">包内文件的相对路径, 后边不带'/', 可以是""</param>
        /// <param name="existMarkFile">检查这个文件, 如果不存在,则说明没解压过, 必须解压</param>
        /// <param name="needCheckFileVersion">true: 表示在文件存在的前提下, 还要检查文件里的版本号是比较旧</param>
        /// <param name="filePathList">需要解压的文件名列表, 可以包含路径, 前后没有'/'</param>
        /// <param name="compress">是否需要解压</param>
        /// <param name="onFinishDelegate">完成时的回调</param>
        /// <returns></returns>
        public static IEnumerator ConstructLocalConfigDbFile(string subPath, string existMarkFile, bool needCheckFileVersion, List <string> filePathList, bool compress, Action <bool> onFinishDelegate, MonoBehaviour coroutineMb)
        {
            bool needCache  = false;
            long newVersion = 0;

            if (needCheckFileVersion)
            {
                long oldVersion = long.MinValue;

                string markFilePath = PathUtility.GetLocalUrl4WWW(FileManager.GetStreamingAssetsPath(subPath)) + Path.AltDirectorySeparatorChar + existMarkFile;
                WWW    loader       = new WWW(markFilePath);
                yield return(loader);

                try
                {
                    newVersion = long.Parse(loader.text);
                }
                catch (Exception e)
                {
                    Debug.LogError(e.StackTrace);
                }

                markFilePath = FileManager.GetPersistentDataPath(subPath) + Path.AltDirectorySeparatorChar + existMarkFile;
                if (File.Exists(markFilePath))
                {
                    loader = new WWW(PathUtility.GetLocalUrl4WWW(markFilePath));
                    yield return(loader);

                    try
                    {
                        oldVersion = long.Parse(loader.text);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.Message);
                    }
                }
                else
                {
                    PathUtility.CreateDirectory(Path.GetDirectoryName(markFilePath));
                    WriteFile(markFilePath, oldVersion.ToString());
                }

                if (newVersion > oldVersion || newVersion == 0) // 如果是0的话每次都拷贝
                {
                    needCache = true;
                }
            }
            else
            {
                string checkPath = FileManager.GetPersistentDataPath(subPath) + Path.AltDirectorySeparatorChar + existMarkFile;
                needCache = !File.Exists(checkPath);
            }

            bool copyAllFileSuccess = true;
            int  copyFileCount      = 0;

            if (needCache)
            {
                foreach (var filePath in filePathList)
                {
                    string persistentFilePath = FileManager.GetPersistentDataPath(subPath + Path.AltDirectorySeparatorChar + filePath);
                    string streamingFilePath  = FileManager.GetStreamingAssetsPath(subPath + Path.AltDirectorySeparatorChar + filePath);

                    /// <summary>
                    /// warning!!!!!
                    /// 为什么这么写
                    /// 似乎是ios上独有的问题,如果yield return www的话,如果www请求了一个不存在的地址(或者出错?)
                    /// 那么www会一直等待,永远不会执行到下一句
                    /// 所以在外边套了一层wwwChecker
                    /// coroutineMono 也是为了能开启这个协程
                    /// </summary>
                    WWW www = new WWW(PathUtility.GetLocalUrl4WWW(streamingFilePath));
                    WWWRequestChecker wwwChecker = new WWWRequestChecker(www);
                    yield return(coroutineMb.StartCoroutine(wwwChecker));

                    if (wwwChecker.IsError)
                    {
                        copyAllFileSuccess = false;
                        continue;
                    }

                    byte[] fileBytes = www.bytes;
                    if (compress)
                    {
                    }
                    else
                    {
                        PathUtility.CreateDirectory(Path.GetDirectoryName(persistentFilePath));

                        try
                        {
                            FileStream fs = File.Create(persistentFilePath);
                            fs.Write(fileBytes, 0, fileBytes.Length);
                            fs.Flush();
                            fs.Close();
                        }
                        catch (Exception e)
                        {
                            copyAllFileSuccess = false;
                            Debug.LogError(e);
                        }
                    }

                    wwwChecker.Dispose();
                    copyFileCount++;
                }

                bool executeSuccess = copyAllFileSuccess && (copyFileCount == filePathList.Count);
                if (executeSuccess)
                {
                    string persistentMarkFilePath = FileManager.GetPersistentDataPath(subPath) + Path.AltDirectorySeparatorChar + existMarkFile;
                    PathUtility.CreateDirectory(Path.GetDirectoryName(persistentMarkFilePath));

                    try
                    {
                        WriteFile(persistentMarkFilePath, newVersion.ToString());
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e);

                        bool reTryCountSuccess = false;
                        for (int i = 0; i < 3; i++)
                        {
                            Thread.Sleep(5 + 5 * i);

                            try
                            {
                                WriteFile(persistentMarkFilePath, newVersion.ToString());

                                reTryCountSuccess = true;
                                break;
                            }
                            catch (Exception ex)
                            {
                                Debug.LogException(ex);
                            }
                        }

                        if (!reTryCountSuccess)
                        {
                            copyAllFileSuccess = false;
                        }
                    }

                    if (!copyAllFileSuccess)
                    {
                        Debug.LogError("Execute file copy not success.");
                    }
                }
                else
                {
                    Debug.LogError("Execute file copy not success.");
                }
            }
            else
            {
                Debug.LogWarning("Version checked pass, not copy file from " + FileManager.GetStreamingAssetsPath(subPath) + "  to  " + FileManager.GetPersistentDataPath(subPath));
            }

            if (onFinishDelegate != null)
            {
                onFinishDelegate(copyAllFileSuccess);
            }
            yield return(null);
        }