예제 #1
0
        public static void AcquireUnity(string unityPoolDir, string unitySvnUrl, string unitySvnRev, out string unityExePath, out IFLock unityLock)
        {
            if (DoodleEnv.curPlatform != Platform.OSX)
            {
                throw new NssIntegrationException($"'{nameof(AcquireUnity)}'只能在OS X系统使用!");
            }
            if (!Directory.Exists(unityPoolDir))
            {
                throw new NotDirException(unityPoolDir, nameof(unityPoolDir));
            }

            unityExePath = null;
            unityLock    = null;

            // 遍历目录下所有Unity,返回可以得到写锁的那个
            string    unityAppPath = null;
            var       rootDir      = new DirectoryInfo(unityPoolDir);
            Stopwatch stopwatch    = new Stopwatch();

            stopwatch.Start();
            IFLock    flock     = null;
            RepeateDo repeateDo = new RepeateDo(600);

            repeateDo.Do(() =>
            {
                foreach (var dir in rootDir.GetDirectories("*.app"))
                {
                    flock = FLockUtil.NewFLock(Path.Combine(unityPoolDir, dir.Name, "lock"));
                    if (!flock.TryAcquireExclusiveLock())
                    {
                        continue;
                    }

                    unityAppPath = Path.Combine(unityPoolDir, dir.Name, "Contents/MacOS/Unity");
                    break;
                }

                if (unityAppPath == null)
                {
                    Logger.Log($"没有可用的Unity引擎,已等待{stopwatch.ElapsedMilliseconds / 1000 / 60}分钟...");
                    Thread.Sleep(60 * 1000);
                    return(false);
                }

                return(true);
            });

            repeateDo = new RepeateDo(5);
            repeateDo.IgnoreException <ExecutableException>();
            repeateDo.Do(() => SvnUtil.Sync(unityAppPath, unitySvnUrl, unitySvnRev));

            if (!flock.TryAcquireShareLock())
            {
                throw new ImpossibleException($"之前已经获取了写锁了,获取读锁不可能失败!");
            }

            // 赋执行权限
            CmdUtil.Execute($"chmod -R +x {unityAppPath}");

            unityExePath = Path.Combine(unityAppPath, "Contents/MacOS/Unity");
            unityLock    = flock;
            return;
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.Title = "QiNiu File Backup Tool";
            ConsoleColor consoleColor = Console.ForegroundColor;

            if (args.Length < 2)
            {
                Console.WriteLine("Please input your qiniu username:"******"Please input your qiniu password:"******"login {username} {password}");

            if (!string.IsNullOrWhiteSpace(loginOutput))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(loginOutput);
                return;
            }

            // check buckets
            var checkBucketsOutput = CmdUtil.Execute(qrsctl, "buckets");
            var bucketMatch        = bucketRegex.Match(checkBucketsOutput);

            if (!bucketMatch.Success)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(checkBucketsOutput);
                return;
            }
            var buckets = bucketMatch.Groups[1].Value.Split(' ');

            if (buckets.Length == 0)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("No buckets.");
                return;
            }

            // list and download
            for (int i = 0; i < buckets.Length; i++)
            {
                var bucket    = buckets[i];
                var bucketDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, imagePath, bucket);
                if (!Directory.Exists(bucketDir))
                {
                    Directory.CreateDirectory(bucketDir);
                }

                var markersOutput = CmdUtil.Execute(qrsctl, $@"listprefix {bucket} """"");
                var markers       = markersOutput.Split('\n', StringSplitOptions.RemoveEmptyEntries).Skip(1).ToArray();
                if (markers.Length == 0)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine($"No markers.");
                }
                else
                {
                    Parallel.ForEach(markers, marker =>
                    {
                        var markerDir      = Path.Combine(bucketDir, marker);
                        var downloadOutput = CmdUtil.Execute(qrsctl, $"get {bucket} {marker} {markerDir}");
                        if (downloadOutput != "\n")
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine($"Download {markerDir} failed:{downloadOutput}");
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine($"Download finished, bucket:{bucket}, marker:{marker}, target:{markerDir}");
                        }
                    });
                }
            }

            Console.ForegroundColor = consoleColor;

            Console.WriteLine("QiNiu File Backup Finished.");

            Console.ReadKey();
        }