Exemplo n.º 1
0
 /*public bool ParseArguments (string[] args)
 {
     for (int i = 0; i < args.Length; ++i) {
         switch (args [i]) {
             case "--data.im-in-memory":
                 have_data_im = true;
                 break;
             case "-h":
             case "--help":
                 FileSystem.ShowFuseHelp ("hellofs");
                 Console.Error.WriteLine ("hellofs options:");
                 Console.Error.WriteLine ("    --data.im-in-memory    Add data.im file");
                 return false;
             default:
                 base.MountPoint = args [i];
                 break;
         }
     }
     return true;
 }*/
 public static void Launch(string mountpoint)
 {
     Mono.Fuse.SoundCloud.FS fs = new Mono.Fuse.SoundCloud.FS();
     fs.MountPoint = mountpoint;
     fs.Start();
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            //	Launch the daemon for controlling SoundCloudFS mounts.  The daemon listens for
            //	connections, and handles the organization of the filesystem.
            string SearchParameters = "";
            string FindUser = "";

            btEngine.Engine.Config.BaseSearchURL = btEngine.Engine.Config.BaseSearchURL.Replace("[CLIENTID]", btEngine.Engine.Config.ClientID);

            if(args.Length == 0)
            {
                Console.WriteLine(Engine.EngineName + " " + Engine.EngineVersion);
                Console.WriteLine("Copyright 2012, Brian Murphy");
                Console.WriteLine("www.gurudigitalsolutions.com");
                Console.WriteLine("");
                Console.WriteLine("ERROR: No arguments specified.");
                Console.WriteLine("");
                Console.WriteLine("USAGE:");
                Console.WriteLine("\tsoundcloudfs <mountpoint> [options]");
                //Console.WriteLine(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "soundcloudfs"));

                Environment.Exit(0);
            }

            //	Check if this is a 64-bit or 32-bit environment.  Also list the files available.

            if(Environment.OSVersion.Platform == PlatformID.Unix)
            {
                string curdir = Environment.CurrentDirectory;
                string lookfor = curdir + "/libMonoFuseHelper.so";

                if(File.Exists(lookfor))
                {
                    //	WooHoo, the proper libMonoFuseHelper library was found.
                }
                else
                {
                    //	We need to determine the archetecture that we are running on so that we can
                    //	put the proper libMonoFuseHelper where it belongs.
                    if(Environment.Is64BitOperatingSystem)
                    {
                        File.Copy(curdir + "/libMonoFuseHelper-x64.so", lookfor);
                    }
                    else
                    {
                        File.Copy(curdir + "/libMonoFuseHelper-i686.so", lookfor);
                    }
                }

            }

            Engine.ConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "soundcloudfs");
            if(!System.IO.Directory.Exists(Engine.ConfigPath))
            {
                try
                {
                    System.IO.Directory.CreateDirectory(Engine.ConfigPath);
                }
                catch(Exception ex)
                {
                    Logging.Write("Could not create the configuration directory.");
                    Logging.Write ("\t"+ex.Message);
                    Engine.ConfigPath = "";
                }
            }
            else
            {
                //	Attempt to load the save configuration.
                string configfile = Path.Combine(Engine.ConfigPath, "config.xml");

                if(File.Exists(configfile))
                {
                    try
                    {
                        XmlSerializer s = new XmlSerializer(typeof(SoundCloudFS.Config.Config));
                        TextReader tr = new StreamReader(configfile);
                        Engine.Config = (SoundCloudFS.Config.Config)s.Deserialize(tr);
                        tr.Close();
                    }
                    catch(Exception ex)
                    {
                        Logging.Write("Could not load configuration file.");
                        Logging.Write("\t" + ex.Message);
                    }
                }
                else
                {
                    Engine.Config.Save();
                }
            }

            if(!System.IO.Directory.Exists(Path.Combine(Engine.ConfigPath, "nodes")))
            {
                try
                {
                    System.IO.Directory.CreateDirectory(Path.Combine(Engine.ConfigPath, "nodes"));
                }
                catch(Exception ex)
                {
                    Logging.Write("Could not create FileNode directory.");
                    Logging.Write("------------------------------------");
                    Logging.Write(ex.Message);
                    Logging.Write("------------------------------------");
                }
            }

            foreach(string earg in args)
            {
                if(Config.MountPoint == "") { Config.MountPoint = earg; }
                else
                {
                    //	Mount point is the first argument, and it is already set.
                    if(earg.IndexOf("=") > 0)
                    {
                        string[] splitat = new string[]{"="};
                        string[] parts = earg.Split(splitat, StringSplitOptions.None);

                        //	Check if this is an option for SoundCloudFS, the search or for FUSE
                        if(parts[0].ToLower() == "filenameformat" || parts[0].ToLower() == "fnf")
                        {
                            Engine.Config.FilenameFormat = parts[1];
                        }
                        else if(parts[0].ToLower() == "byuser")
                        {
                            FindUser = parts[1];
                        }
                        else if(parts[0].ToLower() == "autosavenodes")
                        {
                            if(parts[1].ToLower() == "false"
                               || parts[1].ToLower() == "no"
                               || parts[1].ToLower() == "0")
                            {
                                Engine.Config.AutoSaveNodes = false;
                            }
                            else { Engine.Config.AutoSaveNodes = true; }
                        }
                        else if(parts[0].ToLower() == "decay")
                        {
                            if(parts[1].ToLower() == "nodecay")
                            {
                                Engine.Config.DecayTime = -1;
                            }
                            else
                            {
                                int dtime = 0;
                                if(!Int32.TryParse(parts[1], out dtime))
                                {
                                    Logging.Write("The decay time specified was invalid.");
                                }
                                else
                                {
                                    if(dtime > 0) { Engine.Config.DecayTime = dtime; }
                                    else { Logging.Write("The decay time specified was invalid."); }
                                }
                            }
                        }
                        else if(parts[0].ToLower() == "mountuid"
                                || parts[0].ToLower() == "uid")
                        {
                            int tuid = 0;
                            if(Int32.TryParse(parts[1], out tuid))
                            {
                                Engine.Config.UserID = tuid;
                            }
                        }
                        else if(parts[0].ToLower() == "mountgid"
                                || parts[0].ToLower() == "gid")
                        {
                            int tgid = 0;
                            if(Int32.TryParse(parts[1], out tgid))
                            {
                                Engine.Config.GroupID = tgid;
                            }
                        }
                        else if(parts[0].ToLower() == "mountuser"
                                || parts[0].ToLower() == "uname")
                        {
                            Engine.Config.MountAsUser = parts[1];
                        }
                        else if(parts[0].ToLower() == "mountgroup"
                                || parts[0].ToLower() == "gname")
                        {
                            Engine.Config.MountAsGroup = parts[1];
                        }
                        else
                        {
                            Filters.Add(parts[0], parts[1]);
                            Logging.Write(parts[0] + " = " + parts[1]);
                            if(parts[0].ToLower() == "limit")
                            {
                                int limit = 0;
                                if(Int32.TryParse(parts[1], out limit))
                                {
                                    Engine.Config.QueryLimit = limit;
                                }
                            }
                            else if(parts[0].ToLower() == "offset")
                            {
                                int limit = 0;
                                if(Int32.TryParse(parts[1], out limit))
                                {
                                    Engine.Config.QueryOffset = limit;
                                }
                            }
                            else
                            {
                                SearchParameters = SearchParameters + "&" + parts[0] + "=" + parts[1];
                            }
                        }

                    }
                    else
                    {
                        if(earg.ToLower() == "nodecay")
                        {
                            Engine.Config.DecayTime = -1;
                        }
                        else if(earg.ToLower() == "allowother"
                                || earg.ToLower() == "allowothers"
                                || earg.ToLower() == "allow_other"
                                || earg.ToLower() == "allow_others")
                        {
                            Engine.Config.AllowOthers = true;
                        }
                        else if(earg.ToLower() == "noother"
                                || earg.ToLower() == "noothers"
                                || earg.ToLower() == "no_other"
                                || earg.ToLower() == "no_others")
                        {
                            Engine.Config.AllowOthers = false;
                        }
                    }

                }
            }

            SearchParameters = SearchParameters + "&" + "limit=" + Engine.Config.QueryLimit.ToString();
            SearchParameters = SearchParameters + "&" + "offset=" + Engine.Config.QueryOffset.ToString();

            if(FindUser != null && FindUser != "")
            {
                string FindUserURL = "http://api.soundcloud.com/users?client_id=" + Engine.Config.ClientID + "&q='" + FindUser + "'&limit=1";
                Scrapers.SoundCloudSearch FindUserScrape = new Scrapers.SoundCloudSearch();
                FindUserScrape.ScrapeURL = FindUserURL;

                if(FindUserScrape.TakeTurn())
                {
                    string workwith = FindUserScrape.PageText;
                    workwith = workwith.Substring(workwith.IndexOf("<user>"));
                    workwith = workwith.Replace("<user>", "");
                    string[] splitat = new string[]{"</user>"};
                    string[] parts = workwith.Split(splitat, StringSplitOptions.None);
                    workwith = parts[0].Trim();

                    Logging.Write("---");
                    Logging.Write(workwith);
                    Logging.Write("---");

                    if(workwith.Length > 10)
                    {
                        System.IO.File.WriteAllText("tmpresult.xml", "<user>" + workwith + "</user>");
                        XmlSerializer s = new XmlSerializer(typeof(SoundCloudFS.User));
                        TextReader tr = new StreamReader("tmpresult.xml");
                        SoundCloudFS.User tmpuser = new SoundCloudFS.User();
                        tmpuser = (SoundCloudFS.User)s.Deserialize(tr);
                        tr.Close();
                        System.IO.File.Delete("tmpresult.xml");

                        SearchParameters = SearchParameters + "&user_id=" + tmpuser.ID.ToString();
                        Logging.Write("SearchParams: " + SearchParameters);
                    }
                }
            }

            //	Build a temporary FileTree node system thing.
            /*Engine.FSNodes = new SoundCloudFS.FileTree.Node[Engine.Config.MaxFSNodes];
            Engine.FSNodes[0] = new SoundCloudFS.FileTree.Node(0, "/");
            Engine.FSNodes[0].NodeType = SoundCloudFS.FileTree.Node.NodeTypeTree;
            //int drumstepnode = Engine.FSNodes[0].AddSubNode("drumstep");
            //Engine.FSNodes[drumstepnode].NodeType = SoundCloudFS.FileTree.Node.NodeTypeSearch;
            //Engine.FSNodes[drumstepnode].SearchParameters = SearchParameters;

            int psynode = Engine.FSNodes[0].AddSubNode("psytrance");
            Engine.FSNodes[psynode].NodeType = SoundCloudFS.FileTree.Node.NodeTypeSearch;

            int countrynode = Engine.FSNodes[0].AddSubNode("country");
            Engine.FSNodes[countrynode].NodeType = SoundCloudFS.FileTree.Node.NodeTypeSearch;
            Engine.FSNodes[countrynode].SearchParameters = SearchParameters;

            SoundCloudFS.FileTree.Node.SaveNodes();
            */

            SoundCloudFS.FileTree.Node.LoadNodes();

            Listener[0] = new Listeners(Engine.Config.DaemonPort, "SoundCloudFS Daemon", "scfsd");
            Connections = new IncomingConnections[Config.MaxDaemonConnections];
            for(int ec = 0; ec < Config.MaxDaemonConnections; ec++)
            {
                Connections[ec] = new IncomingConnections(ec);
            }

            Thread daemonthread = new Thread(DaemonHeart);
            daemonthread.Start();

            #if WINDOWS

            if(Environment.OSVersion.Platform != PlatformID.Unix)
            {
                Dokan.SoundCloud.DK dk = new Dokan.SoundCloud.DK();

                if(Engine.Config.MountPoint == null || Engine.Config.MountPoint == "") { dk.MountPoint = args[0]; }
                else { dk.MountPoint = Engine.Config.MountPoint; }

                if(dk.MountPoint.Length == 1) { dk.MountPoint = dk.MountPoint + ":\\"; }
                else if(dk.MountPoint.Length == 2) { dk.MountPoint = dk.MountPoint + "\\"; }
                //else if(dk.MountPoint.Length == 3) { dk.MountPoint = dk.MountPoint + "\\"; }

                dk.Start();

            }
            #else
            if(Environment.OSVersion.Platform == PlatformID.Unix)
            {

                try
                {
                    using (Mono.Fuse.SoundCloud.FS fs = new Mono.Fuse.SoundCloud.FS ())
                    {

                        //Mono.Fuse.SoundCloud.FS fs = new Mono.Fuse.SoundCloud.FS();

                        if(Engine.Config.AllowOthers)
                        {
                            //
                            //	Right now, -o allow_other is enabled by default.  Really though,
                            //	most systems seem to not enable this by default, so this is sort
                            //	of a bug.
                            //

                            string[] fuseopts = new string[]{"-o", "allow_other"};
                            string[] unhandled = fs.ParseFuseArguments(fuseopts);
                        }
                        /*string usemountpoint = "";

                        if(Engine.Config.MountPoint == null || Engine.Config.MountPoint == "") { usemountpoint = args[0]; }
                        else { usemountpoint = Engine.Config.MountPoint; }
                        if(usemountpoint.LastIndexOf("/") == usemountpoint.Length - 1) { usemountpoint = usemountpoint.Substring(0, usemountpoint.Length - 1); }
                        Mono.Fuse.SoundCloud.FS.Launch(usemountpoint);
                        */
                        if(Engine.Config.MountPoint == null || Engine.Config.MountPoint == "") { fs.MountPoint = args[0]; }
                        else { fs.MountPoint = Engine.Config.MountPoint; }
                        if(fs.MountPoint.LastIndexOf("/") == fs.MountPoint.Length - 1) { fs.MountPoint = fs.MountPoint.Substring(0, fs.MountPoint.Length - 1); }
                        fs.Start ();

                    }
                }
                catch(Exception ex)
                {
                    Logging.Write("Exception while launching FUSE filesystem.");
                    Logging.Write(ex.Message);
                }

            }
            #endif
        }