Пример #1
0
        public async Task Run(CommandContext context)
        {
            ConsoleEx.Out
            .WriteLine($"Photon CLI {Configuration.Version}", ConsoleColor.DarkBlue)
            .WriteLine("Checking for updates...", ConsoleColor.DarkCyan);

            var index = await DownloadTools.GetLatestCliIndex();

            var latestVersion = index.Version;

            if (!VersionTools.HasUpdates(Configuration.Version, latestVersion))
            {
                ConsoleEx.Out.WriteLine("CLI is up-to-date.", ConsoleColor.DarkBlue);
                return;
            }

            ConsoleEx.Out.Write("Downloading CLI update ", ConsoleColor.DarkCyan)
            .Write(latestVersion, ConsoleColor.Cyan)
            .WriteLine("...", ConsoleColor.DarkCyan);

            updateDirectory = Path.Combine(Configuration.Directory, "Updates");
            updateFilename  = Path.Combine(updateDirectory, "Photon.Server.msi");

            await DownloadUpdate(index);

            ConsoleEx.Out
            .WriteLine("Download Complete.", ConsoleColor.DarkGreen)
            .WriteLine("Launching installer...", ConsoleColor.DarkCyan);

            StartInstaller();
        }
        private static int Execute(CommandArgs commandArgs, IOutput output)
        {
            Logger.Log.Info("Enter Download Select command.");

            int[]  selectIndex = commandArgs.GetParameter <int[]>(SelectIndex);
            string name        = commandArgs.GetParameter <string>(PodcastName);

            Logger.Log.Info($"Input podcast name is {name}.");
            Logger.Log.Info($"Input select index are {string.Join(";", selectIndex)}.");

            output.WriteLine("Building downloading file...");

            if (!Directory.Exists(ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath))
            {
                Logger.Log.Info($"Create directory, is {ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath}.");

                Directory.CreateDirectory(ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath);
            }

            int res = Opml.DownloadPodcastSelectRelease(name, selectIndex,
                                                        ProgramConfiguration.DownloadConfigurations.DownloadPodcastPath, false,
                                                        ProgramConfiguration.DownloadConfigurations.DownloadProgram);

            if (res != 0)
            {
                Logger.Log.Warn("The input name is NOT in the library.");

                output.WriteLine("Error. Input of Name does not contain in the library.");
                return(0);
            }

            output.WriteLine("Building done");

            Logger.Log.Info("Finish build download file.");

            output.WriteLine("Downloading...");

            if (ProgramConfiguration.DownloadConfigurations.DownloadProgram == DownloadTools.Aria2Name)
            {
                Logger.Log.Info("Start download newly release use aria2.");

                DownloadTools.DownloadAria2(ProgramConfiguration.DownloadConfigurations.DownloadProgramPathName, ProgramConfiguration.DownloadFileName, output);
            }
            else if (ProgramConfiguration.DownloadConfigurations.DownloadProgram == DownloadTools.IdmName)
            {
                Logger.Log.Info("Start download newly release use idm.");

                DownloadTools.DownloadIdm(ProgramConfiguration.DownloadConfigurations.DownloadProgramPathName, ProgramConfiguration.DownloadFileName, output);
            }

            Logger.Log.Info("Finish download.");

            output.WriteLine("Done.");

            return(0);
        }
Пример #3
0
 internal GitRow GetFileInformation(GitRow row)
 {
     try
     {
         var    result    = Task.Run(() => DownloadTools.DownloadFile("https://raw.githubusercontent.com/" + row.Url.Replace("blob", ""))).Result;
         string converted = Encoding.UTF8.GetString(result, 0, result.Length);
         row.Length     = result.Length;
         row.Extension  = row.Name.Split('.')[row.Name.Split('.').Length - 1];
         row.TotalLines = converted.Split('\n').Length;
         return(row);
     }
     catch
     {
         return(row);
     }
 }
Пример #4
0
        public async Task Run(CommandContext context)
        {
            var server = context.Servers.Get(ServerName);

            ConsoleEx.Out.WriteLine("Checking server version...", ConsoleColor.DarkCyan);

            string currentVersion = null;

            await AuthRetryAsync(async() => {
                currentVersion = await WebClient(server, async client => {
                    return((await client.DownloadStringTaskAsync("api/version")).Trim());
                });
            });

            ConsoleEx.Out
            .WriteLine($"Photon Server {currentVersion}", ConsoleColor.DarkBlue)
            .WriteLine("Checking for updates...", ConsoleColor.DarkCyan);

            var serverIndex = await DownloadTools.GetLatestServerIndex();

            if (!VersionTools.HasUpdates(currentVersion, serverIndex.Version))
            {
                ConsoleEx.Out.WriteLine("Server is up-to-date.", ConsoleColor.DarkBlue);

                return;
            }

            await BeginServerUpdate(server, serverIndex);

            ConsoleEx.Out.WriteLine("Server update started. Waiting for restart...", ConsoleColor.Cyan);

            await Task.Delay(3000);

            var timeout = TimeSpan.FromMinutes(2);

            try {
                await Reconnect(server, serverIndex.Version, timeout);

                ConsoleEx.Out.WriteLine("Update completed successfully.", ConsoleColor.DarkGreen);
            }
            catch (TaskCanceledException) {
                throw new ApplicationException($"Server failed to restart within timeout '{timeout}'.");
            }
        }
        private static int Execute(CommandArgs commandArgs, IOutput output)
        {
            Logger.Log.Info("Enter Upgrade command.");

            if (File.GetLastWriteTimeUtc(ProgramConfiguration.PodcastNewlyReleaseInfo) - DateTime.Now > TimeSpan.FromDays(1))
            {
                Logger.Log.Info("Need Upgrade first.");

                output.WriteLine("Updating...");
                Opml.UpdateAllPodcasts(ref output);
                output.WriteLine("Update done.");
            }

            output.WriteLine("Upgrading...");

            if (File.Exists(ProgramConfiguration.PodcastNewlyReleaseInfo))
            {
                if (ProgramConfiguration.DownloadConfigurations.DownloadProgram == DownloadTools.Aria2Name)
                {
                    Logger.Log.Info("Start download newly release use aria2.");
                    output.WriteLine("Start download newly release use aria2.");
                    DownloadTools.DownloadAria2(ProgramConfiguration.DownloadConfigurations.DownloadProgramPathName, ProgramConfiguration.PodcastNewlyReleaseInfo, output);
                }
                else if (ProgramConfiguration.DownloadConfigurations.DownloadProgram == DownloadTools.IdmName)
                {
                    Logger.Log.Info("Start download newly release use idm.");
                    output.WriteLine("Start download newly release use idm.");
                    DownloadTools.DownloadIdm(ProgramConfiguration.DownloadConfigurations.DownloadProgramPathName, ProgramConfiguration.PodcastNewlyReleaseInfo, output);
                }
                File.Delete(ProgramConfiguration.PodcastNewlyReleaseInfo);

                Logger.Log.Info("Finish download newly release.");
                File.Delete(ProgramConfiguration.PodcastNewlyReleaseInfo);
                output.WriteLine("Done.");
            }
            else
            {
                Logger.Log.Info("Nothing upgrade.");
                output.WriteLine("All up-to-date. Nothing download.");
            }

            return(0);
        }
Пример #6
0
        public async Task Run(CommandContext context)
        {
            var server = context.Servers.Get(ServerName);

            ConsoleEx.Out.WriteLine("Retrieving latest agent version...", ConsoleColor.DarkCyan);

            var agentIndex = await DownloadTools.GetLatestAgentIndex();

            var latestVersion = agentIndex.Version;

            ConsoleEx.Out
            .Write("Found Latest Version ", ConsoleColor.DarkCyan)
            .WriteLine(latestVersion, ConsoleColor.Cyan)
            .WriteLine("Checking agent versions...", ConsoleColor.DarkCyan);

            HttpAgentVersionListResponse agentVersionResponse = null;

            await AuthRetryAsync(async() => {
                agentVersionResponse = await WebClient(server, async client => {
                    var json = (await client.DownloadStringTaskAsync("api/agent/versions")).Trim();
                    return(JsonConvert.DeserializeObject <HttpAgentVersionListResponse>(json));
                });
            });

            var updateAgents = new List <string>();

            foreach (var agentVersion in agentVersionResponse.VersionList.OrderBy(x => x.AgentName))
            {
                if (!string.IsNullOrEmpty(agentVersion.Exception))
                {
                    ConsoleEx.Out.Write("Failed to get version of agent ", ConsoleColor.DarkYellow)
                    .Write(agentVersion.AgentName, ConsoleColor.Yellow)
                    .WriteLine($"! {agentVersion.Exception}", ConsoleColor.DarkYellow);

                    continue;
                }

                if (!VersionTools.HasUpdates(agentVersion.AgentVersion, latestVersion))
                {
                    ConsoleEx.Out.Write("Agent ", ConsoleColor.DarkBlue)
                    .Write(agentVersion.AgentName, ConsoleColor.Blue)
                    .WriteLine(" is up-to-date.", ConsoleColor.DarkBlue);

                    continue;
                }

                ConsoleEx.Out.Write("Updating ", ConsoleColor.DarkCyan)
                .Write(agentVersion.AgentName, ConsoleColor.Cyan)
                .Write(" from version ", ConsoleColor.DarkCyan)
                .Write(agentVersion.AgentVersion, ConsoleColor.Cyan)
                .WriteLine(".", ConsoleColor.DarkCyan);

                updateAgents.Add(agentVersion.AgentId);
            }

            if (!updateAgents.Any())
            {
                ConsoleEx.Out.WriteLine("All agents are up-to-date.", ConsoleColor.DarkGreen);
                return;
            }

            // Download update msi

            ConsoleEx.Out.Write("Downloading Agent update ", ConsoleColor.DarkCyan)
            .Write(agentIndex.Version, ConsoleColor.Cyan)
            .WriteLine("...", ConsoleColor.DarkCyan);

            var url = NetPath.Combine(Configuration.DownloadUrl, "agent", agentIndex.Version, agentIndex.MsiFilename);

            var updateDirectory = Path.Combine(Configuration.Directory, "Updates");
            var updateFilename  = Path.Combine(updateDirectory, "Photon.Agent.msi");

            PathEx.CreatePath(updateDirectory);

            using (var client = new WebClient()) {
                await client.DownloadFileTaskAsync(url, updateFilename);
            }

            ConsoleEx.Out.WriteLine("Download Complete.", ConsoleColor.DarkBlue);

            // Perform updates

            var agentIdList = updateAgents.ToArray();

            var startResult = await StartSession(server, agentIdList, updateFilename);

            var sessionId = startResult?.SessionId;

            if (string.IsNullOrEmpty(sessionId))
            {
                throw new ApplicationException($"An invalid session-id was returned! [{sessionId}]");
            }

            var position = 0;

            while (true)
            {
                var data = await UpdateOutput(server, sessionId, position);

                if (data == null)
                {
                    throw new ApplicationException("An empty session-output response was returned!");
                }

                if (data.IsComplete)
                {
                    break;
                }

                if (!data.IsModified)
                {
                    await Task.Delay(PollIntervalMs);

                    continue;
                }

                position = data.NewLength;

                ConsoleEx.Out.WriteLine(data.NewText, ConsoleColor.Gray);
            }

            Result = await GetResult(server, sessionId);

            ConsoleEx.Out.WriteLine("Update completed successfully.", ConsoleColor.DarkGreen);
        }
Пример #7
0
    IEnumerator Start()
    {
        guid      = PlayerPrefs.GetString("guid");
        remoteURL = PlayerPrefs.GetString("url");
        // create download helper
        dt         = gameObject.AddComponent <DownloadTools>() as DownloadTools;
        dt.message = "loading parts for " + guid;


        // get platform name
        platform = dt.GetPlatform();

        // try to get manifest
        WWW www = null;

        yield return(StartCoroutine(dt.openOrDownloadFile(Application.persistentDataPath + "/" + guid + "/", remoteURL, platform, value => www = value)));          //(Application.persistentDataPath + "/" + guid + "/", remoteLocation, platform, value => www = value));

        if (www != null)
        {
            AssetBundleManifest manifest = (AssetBundleManifest)www.assetBundle.LoadAsset("AssetBundleManifest");
            www.assetBundle.Unload(false);

            foreach (string bundle in manifest.GetAllAssetBundles())
            {
                Debug.Log(bundle);
                // load bundle
                WWW bundleWWW = null;
                yield return(StartCoroutine(dt.openOrDownloadFile(Application.persistentDataPath + "/" + guid + "/", remoteURL, bundle, value => bundleWWW = value)));                  //(Application.persistentDataPath + "/" + guid + "/", remoteLocation, platform, value => www = value));

                if (bundleWWW != null)
                {
                    AssetBundle ab = bundleWWW.assetBundle;
                    bundleWWW = null;
                    // Load the object asynchronously
                    AssetBundleRequest request = ab.LoadAssetAsync(bundle);

                    // Wait for completion
                    yield return(request);

                    Instantiate(request.asset);
                    Debug.Log(bundle + " loaded");

                    ab.Unload(false);
                }
                else
                {
                    Debug.Log("Problem accessing bundle: " + bundle);
                    dt.message = "Problem accessing bundle: " + bundle;
                }
            }


            Debug.Log("yay");
            dt.message   = "yay";
            this.enabled = false;
        }
        else
        {
            Debug.Log("Problem accessing site manifest");
            dt.message = "Problem accessing site manifest";
        }
    }
Пример #8
0
    // Use this for initialization
    void Start()
    {
        // create download helper
        dt         = gameObject.AddComponent <DownloadTools>() as DownloadTools;
        dt.message = "started";

        // get platform name
        platform = dt.GetPlatform();
        string remoteLocation = "";
        // write "remote" file to local
        string targetFile = Application.persistentDataPath + "/" + guid + "/remote.txt";

        if (!File.Exists(targetFile))
        {
            Directory.CreateDirectory(Application.persistentDataPath + "/" + guid);

            // write remote URL to file
            remoteLocation = bundleLocation + guid + "/" + platform + "/";
            StreamWriter writer = new StreamWriter(targetFile);
            writer.WriteLine(remoteLocation);
            writer.Close();
            dt.message = "Initialising Site at " + targetFile;
            Debug.Log("Initialising Site at " + targetFile);
        }
        else
        {
            // read remote location
            StreamReader reader = new  StreamReader(targetFile);
            remoteLocation = reader.ReadLine().TrimEnd();
            dt.message     = "Pointing to " + remoteLocation;
            Debug.Log("Pointing to " + remoteLocation);
        }
        PlayerPrefs.SetString("url", remoteLocation);
        // go to main part



        Application.LoadLevel("Main");



//		// check for manifest
//		AssetPath	= Application.persistentDataPath + "/" + guid + "/";
//		bundleFilePath = AssetPath + guid;
//		bundleURL = bundleLocation + guid;
//		if (!File.Exists(bundleFilePath)) {
//			// if directory doesn't exist then create it
//			if (!Directory.Exists(Application.persistentDataPath + "/" + guid)) {
//				Directory.CreateDirectory(Application.persistentDataPath + "/" + guid);
//			}
//
//
//
//			// start downloading
//			yield return StartCoroutine(startDownload(host, uri, bundleFilePath));
//
//		} else {
//			message = "Bundle already downloaded and at " + bundleFilePath;
//			Debug.Log("Bundle already downloaded and at " + bundleFilePath);
//
//		}
    }
Пример #9
0
        private static int Execute(CommandArgs commandArgs, IOutput output)
        {
            Logger.Log.Info("Enter Download command.");

            string podcastsDownloadDirectory = commandArgs.GetOption <string>(DownloadDirectory);

            Logger.Log.Info($"Download directory is {podcastsDownloadDirectory}.");

            if (!Directory.Exists(podcastsDownloadDirectory))
            {
                Logger.Log.Info("Create download directory.");

                try
                {
                    Directory.CreateDirectory(podcastsDownloadDirectory);
                }
                catch
                {
                    Logger.Log.Info($"Directory \"{podcastsDownloadDirectory}\" is not valid.");
                    output.WriteLine("Error. Input of 'dir' is illegal.");
                    return(0);
                }
            }

            bool isSimpleFile = commandArgs.GetFlag(SimpleFile);

            Logger.Log.Info($"Download simple file is {isSimpleFile}.");

            string   date = commandArgs.GetParameter <string>(Date);
            DateTime dt;

            try
            {
                dt = DateTime.ParseExact(date, "yyyyMMdd", new CultureInfo("en-US"));

                Logger.Log.Info($"Download date is {dt.ToString("G")}.");
            }
            catch
            {
                Logger.Log.Warn($"Download date is not valid.");

                output.WriteLine("Error. Input of 'date' is illegal.");
                return(0);
            }

            output.WriteLine("Building downloading file...");

            Logger.Log.Info("Build download file.");

            Opml.DownloadPodcastAfterDate(dt, podcastsDownloadDirectory, isSimpleFile, ProgramConfiguration.DownloadConfigurations.DownloadProgram);

            Logger.Log.Info("Finish build download file.");

            output.WriteLine("Building done");

            if (!isSimpleFile)
            {
                output.WriteLine("Downloading...");

                if (ProgramConfiguration.DownloadConfigurations.DownloadProgram == DownloadTools.Aria2Name)
                {
                    Logger.Log.Info("Start download newly release use aria2.");

                    DownloadTools.DownloadAria2(ProgramConfiguration.DownloadConfigurations.DownloadProgramPathName, ProgramConfiguration.DownloadFileName, output);
                }
                else if (ProgramConfiguration.DownloadConfigurations.DownloadProgram == DownloadTools.IdmName)
                {
                    Logger.Log.Info("Start download newly release use idm.");

                    DownloadTools.DownloadIdm(ProgramConfiguration.DownloadConfigurations.DownloadProgramPathName, ProgramConfiguration.DownloadFileName, output);
                }

                Logger.Log.Info("Finish download.");
                output.WriteLine("Done.");
            }
            return(0);
        }