Пример #1
0
        public string applicationDocumentsDirectory()
        {
            // Get the documents directory
            string dirPath = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true)[0];

            return(dirPath);
        }
Пример #2
0
        private static void DoReport()
        {
            sReportTime.Stop();

            sReportGCCount = System.GC.CollectionCount(System.GC.MaxGeneration) - sReportGCCount;


                        #if PLATFORM_MONOTOUCH
            // dump profile to file
            var dirs = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true);
            if (dirs.Length > 0)
            {
                string id   = DateTime.Now.ToString("u").Replace(' ', '-');
                var    path = Path.Combine(dirs[0], "profile-" + id + ".log");
                Console.WriteLine("Writing profiling report to: {0}", path);
                using (var sw = new StreamWriter(path)) {
                    PrintReport(sw);
                }
            }
                        #endif

            // print to console
            PrintReport(System.Console.Out);

            // pause forever
//			Console.WriteLine("Pausing...");
//			for (;;) {
//				System.Threading.Thread.Sleep(1000);
//			}
        }
Пример #3
0
        public static void Init()
        {
            string docs      = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.All, true).FirstOrDefault();
            string resources = NSBundle.MainBundle.ResourcePath;

            Init(resources, docs);
        }
Пример #4
0
        public string GetFolderPath(EtoSpecialFolder folder)
        {
            NSSearchPathDirectory dir;
            NSSearchPathDomain    domain;

            switch (folder)
            {
            case EtoSpecialFolder.ApplicationResources:
                return(NSBundle.MainBundle.ResourcePath);

            case EtoSpecialFolder.ApplicationSettings:
                Convert(folder, out dir, out domain);
                var path = NSSearchPath.GetDirectories(dir, domain).FirstOrDefault();
                path = System.IO.Path.Combine(path, NSBundle.MainBundle.BundleIdentifier);
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                return(path);

            default:
                Convert(folder, out dir, out domain);
                return(NSSearchPath.GetDirectories(dir, domain).FirstOrDefault());
            }
        }
Пример #5
0
        internal static string GetBasePath(string applicationId)
        {
            if (string.IsNullOrWhiteSpace(applicationId))
            {
                throw new ArgumentException("You must set a ApplicationId for MonkeyCache by using Barrel.ApplicationId.");
            }

            if (applicationId.IndexOfAny(Path.GetInvalidPathChars()) != -1)
            {
                throw new ArgumentException("ApplicationId has invalid characters");
            }

            if (string.IsNullOrWhiteSpace(basePath))
            {
                // Gets full path based on device type.
        #if __IOS__ || __MACOS__
                basePath = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User)[0];
        #elif __ANDROID__
                basePath = Application.Context.CacheDir.AbsolutePath;
        #elif __UWP__ || WINDOWS
                basePath = Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path;
        #else
                basePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
        #endif
            }

            return(Path.Combine(basePath, applicationId));
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            UIImage greenImage = new UIImage("green_button.png").StretchableImage(12, 0);
            UIImage redImage   = new UIImage("red_button.png").StretchableImage(12, 0);

            startButton.SetBackgroundImage(greenImage, UIControlState.Normal);
            startButton.SetBackgroundImage(redImage, UIControlState.Disabled);

            // default output format
            // sample rate of 0 indicates source file sample rate
            outputFormat = AudioFormatType.AppleLossless;
            sampleRate   = 0;

            // can we encode to AAC?
            if (IsAACHardwareEncoderAvailable())
            {
                outputFormatSelector.SetEnabled(true, 0);
            }
            else
            {
                // even though not enabled in IB, this segment will still be enabled
                // if not specifically turned off here which we'll assume is a bug
                outputFormatSelector.SetEnabled(false, 0);
            }

            sourceURL = CFUrl.FromFile("sourcePCM.aif");
            var paths = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);

            destinationFilePath = paths[0] + "/output.caf";
            destinationURL      = NSUrl.FromFilename(destinationFilePath);

            UpdateFormatInfo(fileInfo, sourceURL);
        }
Пример #7
0
        public override void AwakeFromNib()
        {
            base.AwakeFromNib();

            View.Layer      = new CALayer();
            View.WantsLayer = true;

            textContainer                 = new CALayer();
            textContainer.AnchorPoint     = CGPoint.Empty;
            textContainer.Position        = new CGPoint(10, 10);
            textContainer.ZPosition       = 100;
            textContainer.BackgroundColor = NSColor.Black.CGColor;
            textContainer.BorderColor     = NSColor.White.CGColor;
            textContainer.BorderWidth     = 2;
            textContainer.CornerRadius    = 15;
            textContainer.ShadowOpacity   = 0.5f;
            View.Layer.AddSublayer(textContainer);

            textLayer                 = new CATextLayer();
            textLayer.AnchorPoint     = CGPoint.Empty;
            textLayer.Position        = new CGPoint(10, 6);
            textLayer.ZPosition       = 100;
            textLayer.FontSize        = 24;
            textLayer.ForegroundColor = NSColor.White.CGColor;
            textContainer.AddSublayer(textLayer);

            // Rely on setText: to set the above layers' bounds: [self setText:@"Loading..."];
            SetText("Loading...", textLayer);


            var dirs = NSSearchPath.GetDirectories(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.Local);

            foreach (string dir in dirs)
            {
                Console.WriteLine("Dir: {0}", dir);
            }
            string libDir             = dirs[0];
            string desktopPicturesDir = Path.Combine(libDir, "Desktop Pictures");

            Console.WriteLine("DP Dir: {0}", desktopPicturesDir);

            // Launch loading of images on background thread
            Task.Run(async() => {
                await AddImagesFromFolderUrlAsync(desktopPicturesDir);
            });

            repositionButton.Layer.ZPosition  = 100;
            durationTextField.Layer.ZPosition = 100;
            lastWindowSize = Window.Frame.Size;

            Window.DidResize += (sender, e) => {
                if (Math.Abs(lastWindowSize.Width - Window.Frame.Width) > 25 || Math.Abs(lastWindowSize.Height - Window.Frame.Height) > 25)
                {
                    windowIsResizing = true;
                    repositionImages(repositionButton);
                    lastWindowSize   = Window.Frame.Size;
                    windowIsResizing = false;
                }
            };
        }
Пример #8
0
        public static string GetBasePath(string applicationId)
        {
            if (string.IsNullOrWhiteSpace(applicationId))
            {
                throw new ArgumentException("You must set a ApplicationId for Matcha.Sync.Mobile by using DataStore.ApplicationId.");
            }

            if (applicationId.IndexOfAny(Path.GetInvalidPathChars()) != -1)
            {
                throw new ArgumentException("ApplicationId has invalid characters");
            }

            string path;

#if __IOS__ || __MACOS__
            path = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User)[0];
#elif __ANDROID__
            path = Application.Context.CacheDir.AbsolutePath;
#elif __UWP__
            path = Windows.Storage.ApplicationData.Current.LocalCacheFolder.Path;
#else
            path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
#endif
            return(Path.Combine(path, applicationId));
        }
        private NSUrl GetContentKeyDirectory()
        {
            var documentPath = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true).FirstOrDefault();

            if (documentPath == null)
            {
                throw new Exception("Unable to determine library URL");
            }

            var documentUrl = new NSUrl(documentPath, true);

            var contentKeyDirectory = documentUrl.Append(".keys", true);

            if (!NSFileManager.DefaultManager.FileExists(contentKeyDirectory.Path))
            {
                try
                {
                    NSFileManager.DefaultManager.CreateDirectory(contentKeyDirectory.AbsoluteString, false, null);
                }
                catch (Exception ex)
                {
                    throw new Exception($"Unable to create directory for content keys at path: {contentKeyDirectory.Path}", ex);
                }
            }

            return(contentKeyDirectory);
        }
Пример #10
0
        static string GetBasePath()
        {
            string applicationDocumentsDirectory = NSSearchPath.GetDirectories
                                                       (NSSearchPathDirectory.DocumentDirectory,
                                                       NSSearchPathDomain.User, true).LastOrDefault();

            return(Path.Combine(applicationDocumentsDirectory));
        }
Пример #11
0
        public static string GetAppCacheAbsolutePath()
        {
            var    cachepath   = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User);
            var    hideDirPath = NSBundle.MainBundle.BundleIdentifier;
            string appRootPath = cachepath[0] + "/" + hideDirPath + "/";

            return(appRootPath);
        }
Пример #12
0
        public static string imagePathForKey(string key)
        {
            string[] documentDirectories = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true);

            // Get one and only document directory from that list
            string documentDirectory = documentDirectories[0];

            return(Path.Combine(documentDirectory, key));
        }
Пример #13
0
        public static string GetDBPath()
        {
            string[] cachesDirectory = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User, true);

            // Get one and only caches directory from that list
            string directory = cachesDirectory[0];

            return(Path.Combine(directory, "itemCache.db"));
        }
Пример #14
0
        public static string GetDBPath()
        {
            string[] documentDirectories = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true);

            // Get one and only document directory from that list
            string documentDirectory = documentDirectories[0];

            return(Path.Combine(documentDirectory, "shapes.db"));
        }
Пример #15
0
        private static NSUrl GetLocalFilePath()
        {
            var cache        = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User);
            var cachedFolder = cache[0];
            var fileName     = Guid.NewGuid() + ".png";
            var cachedFile   = cachedFolder + fileName;

            return(NSUrl.CreateFileUrl(cachedFile, false, null));
        }
Пример #16
0
        protected override void InitializeDefaultStorage()
        {
            List <string> pathHierarchy = new List <string>();

            pathHierarchy.AddRange(NSSearchPath.GetDirectories(NSSearchPathDirectory.ApplicationSupportDirectory, NSSearchPathDomain.User, true)[0].Split(separationCharacter));
            pathHierarchy.Add("Electrolyte");

            PathHierarchy = pathHierarchy.ToArray();
        }
        public string DefaultDirectory()
        {
            var dirID = NSSearchPathDirectory.ApplicationSupportDirectory;

            var paths = NSSearchPath.GetDirectories(dirID, NSSearchPathDomain.User, true);
            var path  = paths[0];

            return(Path.Combine(path, "CouchbaseLite"));
        }
Пример #18
0
        internal static void OnInited()
        {
            string docsDir      = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.All, true).FirstOrDefault();
            string resourcesDir = NSBundle.MainBundle.ResourcePath;

            InitSdl(resourcesDir, docsDir);
            Sdl.SetMainReady();
            NSFileManager.DefaultManager.ChangeCurrentDirectory(resourcesDir);
        }
Пример #19
0
        /// <summary>
        /// Gets the instance.
        /// </summary>
        /// <returns>The instance.</returns>
        private static LiteDatabase GetInstance()
        {
            var connectionString = new ConnectionString()
            {
                Filename = Path.Combine(NSSearchPath.GetDirectories(NSSearchPathDirectory.LibraryDirectory, NSSearchPathDomain.User)[0], "Clad.db"),
                Mode     = LiteDB.FileMode.Exclusive
            };

            return(new LiteDatabase(connectionString));
        }
Пример #20
0
 private string GetFolder()
 {
     string[] directories = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);
     if (directories.Length > 0)
     {
         string directory = directories[0];
         return(directory);
     }
     return("");
 }
Пример #21
0
        static string GetDirectory(NSSearchPathDirectory directory)
        {
            var dirs = NSSearchPath.GetDirectories(directory, NSSearchPathDomain.User);

            if (dirs == null || dirs.Length == 0)
            {
                // this should never happen...
                return(null);
            }
            return(dirs[0]);
        }
Пример #22
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            var basePath = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User)[0];

            Console.WriteLine($"<<<< BASEPATH {basePath}");

            return(base.FinishedLaunching(app, options));
        }
Пример #23
0
        public static string GetAppUserAbsolutePath()
        {
            var    cachepath   = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User);
            var    hideDirPath = NSBundle.MainBundle.BundleIdentifier;
            string appRootPath = cachepath[0] + "/" + hideDirPath + "/";

            LoginUserDetails userDetail = GlobalAccess.Instance.CurrentUserInfo;

            appRootPath = appRootPath + userDetail.UserFolder;
            return(appRootPath);
        }
Пример #24
0
        static string GetCacheDirectory()
        {
            var dirs = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User);

            if (dirs == null || dirs.Length == 0)
            {
                throw new NotSupportedException();
            }

            return(dirs[0]);
        }
Пример #25
0
        public string GetUserDirectory()
        {
            string[] paths = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User);

            if (paths != null && paths.Length > 0)
            {
                return(paths[0]);
            }

            throw new Exception("Unable to locate Caches directory.");
        }
Пример #26
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            SQLitePCL.Batteries.Init();
            var dbPath = Path.Combine(NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true)[0], "words.db3");

            SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_e_sqlite3());

            Forms.Init();
            LoadApplication(new App(new WordRepository(dbPath)));
            base.DidFinishLaunching(notification);
        }
        static string GetDirectory(NSSearchPathDirectory directory)
        {
            var dirs = NSSearchPath.GetDirectories(directory, NSSearchPathDomain.User);

            if (dirs == null || dirs.Length == 0)
            {
                // this should never happen...
                throw new NotSupportedException("this should never happen...");
                //return null;
            }
            return(dirs[0]);
        }
Пример #28
0
        public override void DidFinishLaunching(NSNotification notification)
        {
            Xamarin.Forms.Forms.Init();

            //TODO: Replace with Xamarin.Essentials API.
            string dataDir = NSSearchPath.GetDirectories(NSSearchPathDirectory.ApplicationSupportDirectory, NSSearchPathDomain.User)[0];

            dataDir = System.IO.Path.Combine(dataDir, "Unjammit");
            // Create dataDir, if it doesnt' exist.
            if (!System.IO.Directory.Exists(dataDir))
            {
                System.IO.Directory.CreateDirectory(dataDir);
            }

            Jammit.Forms.App.AllowedFileTypes = new string[] { "com.pkware.zip-archive" };
            Jammit.Forms.App.DataDirectory    = dataDir;

#if false
            Jammit.Forms.App.PlayerFactory =
                async(media) => await System.Threading.Tasks.Task.Run(() => new Audio.AppleJcfPlayer(media));
#else
            Jammit.Forms.App.PlayerFactory = async(media) => await System.Threading.Tasks.Task.Run(() =>
            {
                var player = new Audio.NAudioJcfPlayer(
                    media,
                    new Audio.AVAudioWavePlayer()
                {
                    DesiredLatency = 60, NumberOfBuffers = 2
                },
                    System.IO.Path.Combine(dataDir, "Tracks"),
                    Forms.Resources.Assets.Stick);

                player.TimerAction = () =>
                {
                    Xamarin.Forms.Device.StartTimer(new System.TimeSpan(0, 0, 1), () =>
                    {
                        Xamarin.Forms.Device.BeginInvokeOnMainThread(() => player.NotifyPositionChanged());

                        return(player.State == Audio.PlaybackStatus.Playing);
                    });
                };

                return(player);
            });
#endif

            Jammit.Forms.App.MediaLoader = new Model.FileSystemJcfLoader(dataDir);

            LoadApplication(new Jammit.Forms.App());

            base.DidFinishLaunching(notification);
            _window.Toolbar.Visible = false;
        }
Пример #29
0
 private static string  GetProfileLogDir()
 {
                 #if PLATFORM_MONOTOUCH || PLATFORM_MONOMAC
     // dump profile to file
     var dirs = NSSearchPath.GetDirectories(NSSearchPathDirectory.DocumentDirectory, NSSearchPathDomain.User, true);
     if (dirs.Length > 0)
     {
         return(dirs[0]);
     }
                 #endif
     return(null);
 }
Пример #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="notificationImage"></param>
        /// <returns></returns>
        protected virtual async Task <UNNotificationAttachment> GetNativeImage(NotificationImage notificationImage)
        {
            if (notificationImage is null || notificationImage.HasValue == false)
            {
                return(null);
            }

            NSUrl imageAttachment = null;

            if (string.IsNullOrWhiteSpace(notificationImage.ResourceName) == false)
            {
                imageAttachment = NSBundle.MainBundle.GetUrlForResource(Path.GetFileNameWithoutExtension(notificationImage.ResourceName), Path.GetExtension(notificationImage.ResourceName));
            }
            if (string.IsNullOrWhiteSpace(notificationImage.FilePath) == false)
            {
                if (File.Exists(notificationImage.FilePath))
                {
                    imageAttachment = NSUrl.CreateFileUrl(notificationImage.FilePath, false, null);
                }
            }
            if (notificationImage.Binary != null && notificationImage.Binary.Length > 0)
            {
                using (var stream = new MemoryStream(notificationImage.Binary))
                {
                    var image          = Image.FromStream(stream);
                    var imageExtension = image.RawFormat.ToString();

                    var cache = NSSearchPath.GetDirectories(NSSearchPathDirectory.CachesDirectory,
                                                            NSSearchPathDomain.User);
                    var cachesFolder = cache[0];
                    var cacheFile    = $"{cachesFolder}{NSProcessInfo.ProcessInfo.GloballyUniqueString}.{imageExtension}";

                    if (File.Exists(cacheFile))
                    {
                        File.Delete(cacheFile);
                    }

                    await File.WriteAllBytesAsync(cacheFile, notificationImage.Binary);

                    imageAttachment = NSUrl.CreateFileUrl(cacheFile, false, null);
                }
            }

            if (imageAttachment is null)
            {
                return(null);
            }

            var options = new UNNotificationAttachmentOptions();

            return(UNNotificationAttachment.FromIdentifier("image", imageAttachment, options, out _));
        }