コード例 #1
0
        public string OpenDirectory(string directoryPath)
        {
            DebugHandler.TraceMessage("OpenDirectory Called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Directory Path: " + directoryPath, DebugSource.TASK, DebugType.PARAMETERS);

            try
            {
#if __ANDROID__
                Android.Net.Uri        uri    = Android.Net.Uri.Parse(directoryPath);
                Android.Content.Intent intent = new Android.Content.Intent(Android.Content.Intent.ActionView);
                intent.SetDataAndType(uri, "*/*");
                intent.SetFlags(Android.Content.ActivityFlags.ClearWhenTaskReset | Android.Content.ActivityFlags.NewTask);
                Android.App.Application.Context.StartActivity(Android.Content.Intent.CreateChooser(intent, "Choose File Explorer"));
#else
                if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.Linux)
                {
                    Process.Start("xdg-open", directoryPath);
                }
                else if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.OsX)
                {
                    Process.Start("open", directoryPath);
                }
                else
                {
                    Process.Start("explorer.exe", directoryPath);
                }
#endif
                JsonSuccess report = new JsonSuccess()
                {
                    message = "Succesfully opened folder with path: " + directoryPath
                };

                return(report.ToJson());
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage("Could not open directory: " + e.ToString(), DebugSource.TASK, DebugType.WARNING);

                JsonError jsonError = new JsonError
                {
                    type         = "open_directory_failed",
                    errormessage = "Could not open directory.",
                    errortype    = "exception"
                };

                return(jsonError.ToJson());
            }
        }
コード例 #2
0
ファイル: FileHandler.cs プロジェクト: silverboy2003/Library
        public string OpenFile(string filePath, string fileName = null)
        {
            DebugHandler.TraceMessage("OpenFile called", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("FilePath: " + filePath, DebugSource.TASK, DebugType.PARAMETERS);

            string fullFilePath = filePath;

            if (fileName != null)
            {
                DebugHandler.TraceMessage("FileName: " + fileName, DebugSource.TASK, DebugType.PARAMETERS);

                fullFilePath = Path.Combine(filePath, fileName);

                DebugHandler.TraceMessage("Full Filepath: " + fullFilePath, DebugSource.TASK, DebugType.INFO);
            }

            try
            {
                for (int i = 0; i < 20; i++)
                {
                    if (File.Exists(fullFilePath))
                    {
#if __ANDROID__
                        Android.Net.Uri uri    = Android.Net.Uri.Parse(fullFilePath);
                        Intent          intent = new Intent(Intent.ActionView);
                        intent.SetDataAndType(uri, "video/*");
                        intent.SetFlags(ActivityFlags.ClearWhenTaskReset | ActivityFlags.NewTask);
                        Android.App.Application.Context.StartActivity(intent);
#else
                        if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.OsX)
                        {
                            Process.Start("open", fullFilePath);
                        }
                        else
                        {
                            var p = new Process
                            {
                                StartInfo = new ProcessStartInfo(fullFilePath)
                                {
                                    UseShellExecute = true
                                }
                            };
                            p.Start();
                        }
#endif
                        JsonSuccess report = new JsonSuccess()
                        {
                            message = "Succesfully opened file with path: " + fullFilePath
                        };
                        return(report.ToJson());
                    }
                    Thread.Sleep(200);
                }

                JsonError jsonError = new JsonError
                {
                    type         = "open_file_failed",
                    errormessage = "Could not open file but didn't throw exception.",
                    errortype    = "warning",
                    exception    = "none"
                };

                DebugHandler.TraceMessage("Could not open file but didn't throw exception, file: " + fullFilePath, DebugSource.TASK, DebugType.WARNING);

                return(jsonError.ToJson());
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage("Could not open file. " + fullFilePath, DebugSource.TASK, DebugType.WARNING);
                DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING);


                JsonError jsonError = new JsonError
                {
                    type         = "open_file_failed",
                    errormessage = "Could not open file.",
                    errortype    = "exception",
                    exception    = e.ToString()
                };
                return(jsonError.ToJson());
            }
        }
コード例 #3
0
        public async Task <JsonVersionInfo> GetLatestVersionDesktop(bool release)
        {
            DebugHandler.TraceMessage("GetLatestVersionDesktop Called.", DebugSource.TASK, DebugType.ENTRY_EXIT);
            DebugHandler.TraceMessage("Is release mode: " + release.ToString(), DebugSource.TASK, DebugType.PARAMETERS);


            JsonVersionInfo versionInfo = new JsonVersionInfo();

            try
            {
                HttpClient client = new HttpClient();

                var request = new HttpRequestMessage(HttpMethod.Get, "https://api.github.com/repos/littleweeb/Desktop/releases?access_token=018003ade567151524c10210f0bd97b05b6ec96b");
                request.Headers.Add("Accept", "application/vnd.github.v3+json");
                request.Headers.Add("User-Agent", "LittleWeeb");

                var response = await client.SendAsync(request);


                if (response.IsSuccessStatusCode)
                {
                    DebugHandler.TraceMessage("Succesfully retreived releases!", DebugSource.TASK, DebugType.INFO);

                    string json = await response.Content.ReadAsStringAsync();

                    DebugHandler.TraceMessage("Releases: " + json, DebugSource.TASK, DebugType.INFO);
                    JArray jsonResult = JArray.Parse(json);

                    foreach (JObject latestRelease in jsonResult.Children <JObject>())
                    {
                        string mode = "develop";
                        if (release)
                        {
                            mode = "master";
                        }
                        if (latestRelease.Value <string>("target_commitish") == mode)
                        {
                            string latestTag = latestRelease.Value <string>("tag_name");

                            string tagShouldContain = "win";
                            if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.Linux)
                            {
                                tagShouldContain = "linux";
                            }
                            else if (UtilityMethods.CheckOperatingSystems() == UtilityMethods.OperatingSystems.OsX)
                            {
                                tagShouldContain = "mac";
                            }

                            if (latestTag.Contains(tagShouldContain))
                            {
                                string latestVersion = latestTag.Split('_')[0];
                                string releaseUrl    = latestRelease.Value <string>("html_url");
                                string date          = latestRelease.Value <string>("published_at");

                                JArray assets = latestRelease.Value <JArray>("assets");

                                JObject latestAsset = assets.Last.ToObject <JObject>();

                                string latestDownload = latestAsset.Value <string>("browser_download_url");
                                string latestFileName = latestAsset.Value <string>("name");

                                versionInfo.newbuild            = latestFileName.Split('.')[latestFileName.Split('.').Length - 2];
                                versionInfo.newversion          = latestVersion;
                                versionInfo.release_url         = releaseUrl;
                                versionInfo.direct_download_url = latestDownload;
                                versionInfo.file_name           = latestFileName;
                                versionInfo.date            = date;
                                versionInfo.release_version = mode;
                                return(versionInfo);
                            }
                        }
                    }

                    DebugHandler.TraceMessage("No matching releases found!", DebugSource.TASK, DebugType.INFO);
                    return(versionInfo);
                }
                else
                {
                    DebugHandler.TraceMessage("Failed retreiving releases!", DebugSource.TASK, DebugType.WARNING);
                    return(versionInfo);
                }
            }
            catch (Exception e)
            {
                DebugHandler.TraceMessage(e.ToString(), DebugSource.TASK, DebugType.WARNING);

                return(versionInfo);
            }
        }