コード例 #1
0
ファイル: Runtime.cs プロジェクト: sundowndk/sBook
        public static void Initialize()
        {
            try
            {
                SetDefaults ();

                sConsole.Menu.AddItem ("addins", "sbook", "Facebook", "addins/sbook/", 0);

                Include.Add (sConsole.Enums.IncludeType.Javascript, "/js/sbook.js", "SBOOK", 101);

                // Create symlinks if they dont exist.
                if (!Directory.Exists (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "sConsole/data/content/addins/sbook"))
                {
                    UnixFileInfo dirinfo = new UnixFileInfo (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "sBook/data/content/addins/sbook");
                    dirinfo.CreateSymbolicLink (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "sConsole/data/content/addins/sbook");
                }

                if (!Directory.Exists (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "sConsole/data/html/xml/addins/sbook"))
                {
                    UnixFileInfo dirinfo = new UnixFileInfo (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "sBook/data/html/xml/addins/sbook");
                    dirinfo.CreateSymbolicLink (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "sConsole/data/html/xml/addins/sbook");
                }

                if (!File.Exists (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "sConsole/data/html/js/sbook.js"))
                {
                    UnixFileInfo dirinfo = new UnixFileInfo (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "sBook/data/html/js/sbook.js");
                    dirinfo.CreateSymbolicLink (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "sConsole/data/html/js/sbook.js");
                }
            }
            catch (Exception exception)
            {
                // LOG: LogDebug.ExceptionUnknown
            //				SorentoLib.Services.Logging.LogDebug (string.Format (SorentoLib.Strings.LogDebug.ExceptionUnknown, "SFORM.INITIALIZE", exception.Message));
            }
        }
コード例 #2
0
ファイル: DirectoryTest.cs プロジェクト: GirlD/mono
	[Test] //BXC #12461
	public void EnumerateFilesListSymlinks ()
	{
		if (!RunningOnUnix)
			return;

		var afile = Path.Combine (TempFolder, "afile.src");
		var bfile = Path.Combine (TempFolder, "bfile.src");
		var cdir = Path.Combine (TempFolder, "cdir.src");

		File.AppendAllText (afile, "hello");
		var info = new UnixFileInfo (afile);
		info.CreateSymbolicLink (bfile);
		Directory.CreateDirectory (cdir);

		var files0 = Directory.GetFiles (TempFolder, "*.src");
		Array.Sort (files0);
		Assert.AreEqual (2, files0.Length, "#1");
		Assert.AreEqual (afile, files0 [0], "#2");
		Assert.AreEqual (bfile, files0 [1], "#3");

#if NET_4_0
		var files1 = new List<string> (Directory.EnumerateFiles (TempFolder, "*.src")).ToArray ();
		Array.Sort (files1);
		Assert.AreEqual (2, files1.Length, "#1.b");
		Assert.AreEqual (afile, files1 [0], "#2.b");
		Assert.AreEqual (bfile, files1 [1], "#3.b");
#endif

		var files2 = Directory.GetFileSystemEntries (TempFolder, "*.src");
		Array.Sort (files2);
		Assert.AreEqual (3, files2.Length, "#1.c");
		Assert.AreEqual (afile, files2 [0], "#2.c");
		Assert.AreEqual (bfile, files2 [1], "#3.c");
		Assert.AreEqual (cdir, files2 [2], "#4.c");

#if NET_4_0
		var files3 = new List<string> (Directory.EnumerateFileSystemEntries (TempFolder, "*.src")).ToArray ();
		Array.Sort (files3);
		Assert.AreEqual (3, files3.Length, "#1.d");
		Assert.AreEqual (afile, files3 [0], "#2.d");
		Assert.AreEqual (bfile, files3 [1], "#3.d");
		Assert.AreEqual (cdir, files3 [2], "#4.d");
#endif
	}
コード例 #3
0
ファイル: MBFile.cs プロジェクト: emtees/old-code
		public void LinkFromOrCopyTo (MBFile f, IBuildContext ctxt)
		{
		    // FIXME: like MakeExecutable, probably a hack.
		    string path = GetPath (ctxt);

		    if (!RuntimeEnvironment.MonoUnixSupported) {
			// emulate with copying
			CopyTo (f, ctxt);
			return;
		    }

		    // Try and emulate the copy semantics by obliterating
		    // f if it already exists.

		    string other = f.GetPath (ctxt);

		    try {
			File.Delete (other);
		    } catch (IOException) {
		    }

		    // FIXME: does this create absolute paths always?
		    // that would be highly lame.

		    UnixFileInfo ufi = new UnixFileInfo (path);
		    ctxt.Logger.Log ("io.file_link", other + " -> " + path);
		    ufi.CreateSymbolicLink (other);
		}
コード例 #4
0
        //private Stack<DatabaseTrackInfo> stk=new Stack<DatabaseTrackInfo>();
        public void ImportSheet(CueSheet s)
        {
            if (import_manager==null) {
                try {
                    import_manager = new LibraryImportManager (false);
                    /*import_manager.ImportResult+=delegate(object sender,DatabaseImportResultArgs args) {
                        DatabaseTrackInfo trk=args.Track;
                        stk.Push (trk);
                    };*/
                } catch (Exception ex) {
                    Hyena.Log.Error (ex.ToString ());
                }
            }

            Hyena.Log.Debug ("Importsheet: Starting transaction");
            int i,N;
            for(i=0,N=s.nEntries ();i<N;i++) {
                try {
                    CueSheetEntry e=s.entry (i);
                    string file=e.file ();
                    string uuid=Regex.Replace(e.id (),"\\s","_");
                    string ext=".mp3";

                    string uid=Guid.NewGuid ().ToString ();
                    string u1=uid.Substring (0,1);
                    string u2=uid.Substring (0,2);
                    string dir=basedir+"/.banshee/"+u1;
                    if (!Directory.Exists (dir))  {
                        Directory.CreateDirectory(dir);
                    }
                    dir+="/"+u2;
                    if (!Directory.Exists(dir)) {
                        Directory.CreateDirectory(dir);
                    }
                    uuid=dir+"/"+uuid+ext;

                    UnixFileInfo f=new UnixFileInfo(file);
                    if (File.Exists (uuid)) { File.Delete(uuid); }
                    //f.CreateLink (uuid);
                    f.CreateSymbolicLink(uuid);

                    DatabaseTrackInfo trk=import_manager.ImportTrack(uuid);
                    //File.Delete (uuid);
                    /*if (trk==null) {
                        Hyena.Log.Warning ("track = null (file="+e.file ()+")");
                        if (stk.Count>0) { trk=stk.Pop (); }
                    }*/

                    if (trk==null) {
                        Hyena.Log.Error ("track = null (file="+e.file ()+")");
                    } else {
                        Hyena.Log.Information ("track!=null (file="+e.file ()+")");
                        //MySource.DbConnection.BeginTransaction();
                        trk.PartOfCue=1;
                        trk.CueAudioFile=e.file ();
                        trk.AlbumTitle=s.title ();
                        //trk.Album=s.title ();
                        trk.AlbumArtist=s.performer ();
                        trk.Composer=(e.Composer=="") ? s.composer () : e.Composer;
                        //trk.ArtworkId=s.getArtId ();
                        //trk.Artist=
                        trk.ArtistName=(e.performer ()=="") ? s.performer () : e.performer ();
                        trk.TrackTitle=e.title ();
                        trk.TrackNumber=i+1;
                        trk.Genre=s.genre ();
                        trk.BeginOffset=e.BeginOffset;
                        trk.EndOffset=e.EndOffset;
                        //trk.Uri=trk.CueAudioUri;
              						//trk.MediaAttributes = TrackMediaAttributes.ExternalResource;
                        //trk.PrimarySource = ServiceManager.SourceManager.MusicLibrary;

                        trk.Save ();
                        //MySource.DbConnection.CommitTransaction();
                    }
                } catch (Exception ex) {
                    Hyena.Log.Error (ex.ToString ());
                }
            }
            import_manager.NotifyAllSources ();
        }
コード例 #5
0
        private void onStartSync(object o, EventArgs args)
        {
            Hyena.Log.Debug ("Start of Sync triggered!");

            var options = View.GetOptions ();

            // target directory to copy to
            Hyena.Log.DebugFormat ("Target folder is set to: {0}", options.TargetFolder);

            // count all files for progress bar
            int totalFiles = 0;
            foreach (var playlist in options.SelectedPlaylists) {
                totalFiles += playlist.Tracks.Count ();
            }
            View.Progress.Text = AddinManager.CurrentLocalizer.GetString ("Preparing sync");
            var progress_step = 1f / totalFiles;
            var current_progress = 0f;

            // begin sync worker thread
            ThreadStart syncStart = delegate()
            {
                Hyena.Log.Debug ("Sync thread started!");
                // foreach playlist
                foreach (var playlist in options.SelectedPlaylists) {

                    Stream m3u_stream = null;
                    StreamWriter m3u_writer = null;

                    if (options.CreateM3u) {
                        var m3u_fileUri = new StringBuilder ().Append (options.TargetFolder)
                         .Append (Path.DirectorySeparatorChar).Append (playlist.Name)
                         .Append (".m3u").ToString ();

                        m3u_stream = Banshee.IO.File.OpenWrite (new SafeUri (m3u_fileUri), true);
                        Log.DebugFormat ("opened m3u playlist for writing: {0}", m3u_fileUri);
                        m3u_writer = new StreamWriter (m3u_stream, System.Text.Encoding.UTF8);
                    }

                    // for each contained file
                    foreach (var track in playlist.Tracks) {
                        // get filename part of path
                        var dest_path_suffix = track.GetFilepathSuffix (options.SubfolderDepth);

                        // we dont want %20 etc. in the m3u since some android devices delete
                        // playlists with that encoding in it (i.e. galaxy S)
                        Hyena.Log.DebugFormat ("filename for m3u file is {0}", dest_path_suffix);

                        // assemble new Uri of target track
                        var destUri = new SafeUri (new StringBuilder ().Append (options.TargetFolder)
                            .Append (Path.DirectorySeparatorChar)
                            .Append (dest_path_suffix).ToString ());

                        // create subfolders if necessary
                        string dest_path = options.TargetFolder;
                        var folders = track.GetSubdirectories (options.SubfolderDepth);
                        try {
                            for (int i=0; i < folders.Count (); i++) {
                                dest_path += folders [i] + "/";
                                Hyena.Log.DebugFormat ("creating folder {0}", dest_path);
                                if (!Banshee.IO.Directory.Exists (dest_path))
                                    Banshee.IO.Directory.Create (new SafeUri (dest_path));
                            }
                        } catch {
                            // folder creation failed, this is fatal, stop
                            // TODO display a error popup
                            break;
                        }

                        // copy file to selected folder
                        try {
                            var destExists = Banshee.IO.File.Exists (destUri);

                            if (options.OverwriteExisting || !destExists) {
                                if (options.CreateSymLinks) {
                                    var trackFilePath = SafeUri.UriToFilename (track.Uri);
                                    var destFilePath = SafeUri.UriToFilename (destUri);

                                    if (track.Uri.IsLocalPath) {
                                        var target = new UnixFileInfo (trackFilePath);

                                        // symbolic links need manual deletion,
                                        // otherwise an exception is thrown in CreateSymbolicLink()
                                        if (destExists) {
                                            var dest = new UnixFileInfo (destFilePath);
                                            dest.Delete ();
                                        }

                                        target.CreateSymbolicLink (destFilePath);
                                    } else {
                                        Hyena.Log.ErrorFormat ("Cannot create symlink to remote path {0} in {1}, skipping", track.Uri, destFilePath);
                                    }
                                } else {
                                    Banshee.IO.File.Copy (track.Uri, destUri, true);
                                }
                                Hyena.Log.DebugFormat ("Copying {0} to {1}", track.Uri, destUri);
                            } else
                                Hyena.Log.Debug ("Not overwriting existing file {0}", destUri);
                        } catch {
                            Hyena.Log.ErrorFormat ("Error copying file {0} to {1}, skipping", track.Uri, destUri);
                        }

                        // increment the progressbar
                        current_progress += progress_step;
                        if (current_progress > 1.0f)
                            current_progress = 1.0f;

                        Gtk.Application.Invoke (delegate {
                            View.Progress.Fraction = current_progress;
                            View.Progress.Text = AddinManager.CurrentLocalizer.GetString ("Copying") + " " + track.Filepath;
                            Gtk.Main.IterationDo (false);
                        });

                        if (options.CreateM3u) {
                            m3u_writer.Write (track.CreateM3uEntry (options.SubfolderDepth));
                        }
                    }
                    // close the m3u file before processing next playlist
                    if (options.CreateM3u) {
                        Hyena.Log.Debug ("closing m3u filedescriptor");
                        m3u_writer.Close ();
                        m3u_writer.Dispose ();
                    }
                    Hyena.Log.Debug ("sync process finished");
                }

                Gtk.Application.Invoke (delegate {
                    View.Progress.Text = AddinManager.CurrentLocalizer.GetString ("Done!");
                    View.Progress.Fraction = 1f;
                    Gtk.Main.IterationDo (false);
                });
                Hyena.Log.Debug ("sync DONE, returning");
                return;
            };
            // end of sync worker thread

            syncThread = new Thread (syncStart);
            syncThread.Start ();
            return;
        }
コード例 #6
0
ファイル: Media.cs プロジェクト: sundowndk/Sorento
        public void Update()
        {
            // Check if data still exists.
            if (!File.Exists (this.DataPath))
            {
                // EXCEPTION: Exception.MediaSaveData
                throw new Exception (string.Format (Strings.Exception.MediaSaveData, this._id));
            }

            if (this._type != this._temptype)
            {
                string source = string.Empty;
                string destination = string.Empty;

                switch (this._type)
                {
                    case Enums.MediaType.Temporary:
                    {
                        source = Services.Config.Get<string> (Enums.ConfigKey.path_temp);
                        break;
                    }

                    case Enums.MediaType.TemporaryPublic:
                    {
                        source = Services.Config.Get<string> (Enums.ConfigKey.path_temp);
                        break;
                    }

                    case Enums.MediaType.Public:
                    {
                        source = Services.Config.Get<string> (Enums.ConfigKey.path_media);
                        break;
                    }

                    case Enums.MediaType.Restricted:
                    {
                        source = Services.Config.Get<string> (Enums.ConfigKey.path_media);
                        break;
                    }
                }

                switch (this._temptype)
                {
                    case Enums.MediaType.Temporary:
                    {
                        destination = Services.Config.Get<string> (Enums.ConfigKey.path_temp);
                        break;
                    }

                    case Enums.MediaType.TemporaryPublic:
                    {
                        destination = Services.Config.Get<string> (Enums.ConfigKey.path_temp);
                        break;
                    }

                    case Enums.MediaType.Public:
                    {
                        destination = Services.Config.Get<string> (Enums.ConfigKey.path_media);
                        break;
                    }

                    case Enums.MediaType.Restricted:
                    {
                        destination = Services.Config.Get<string> (Enums.ConfigKey.path_media);
                        break;
                    }
                }

                if ((this._path != this._temppath) || (this._type != this._temptype))
                {
                    // Remove old symlink if needed.
                    if ((this._type == Enums.MediaType.Public) || (this._type == Enums.MediaType.TemporaryPublic))
                    {
                        File.Delete (Services.Config.Get<string> (Enums.ConfigKey.path_publicmedia) + this._path);
                    }
                }

                if (source != destination)
                {
                    FileInfo file = new FileInfo (source + this._id);
                    file.MoveTo (destination + this._id);
                }
            }

            this._path = this._temppath;
            this._type = this._temptype;

            // Create new symlink if needed.
            if ((this._temptype == Enums.MediaType.Public) || (this._temptype == Enums.MediaType.TemporaryPublic))
            {
                // Check if path exists, if not create it.
                if (!System.IO.Directory.Exists (Services.Config.Get<string> (Enums.ConfigKey.path_publicmedia) + System.IO.Path.GetDirectoryName (this._temppath)))
                {
                    System.IO.Directory.CreateDirectory (Services.Config.Get<string> (Enums.ConfigKey.path_publicmedia) + System.IO.Path.GetDirectoryName (this._temppath));
                }

                // Create a new symlink.
                UnixFileInfo unixfileinfo = new UnixFileInfo (this.DataPath);
                unixfileinfo.CreateSymbolicLink (Services.Config.Get<string> (Enums.ConfigKey.path_publicmedia) + this._temppath);
            }

            string path = string.Empty;

            switch (this._type)
            {
                case Enums.MediaType.Temporary:
                {
                    path = Services.Config.Get<string> (Enums.ConfigKey.path_temp);
                    break;
                }

                case Enums.MediaType.TemporaryPublic:
                {
                    path = Services.Config.Get<string> (Enums.ConfigKey.path_temp);
                    break;
                }

                case Enums.MediaType.Public:
                {
                    path = Services.Config.Get<string> (Enums.ConfigKey.path_media);
                    break;
                }

                case Enums.MediaType.Restricted:
                {
                    path = Services.Config.Get<string> (Enums.ConfigKey.path_media);
                    break;
                }
            }

            // Get filesize
            FileInfo fileinfo = new FileInfo (path + this._id);
            this._size = fileinfo.Length;

            // Get mimetype
            this._mimetype = SNDK.IO.GetMimeType (path + this._id);
        }
コード例 #7
0
ファイル: Media-old.cs プロジェクト: sundowndk/Sorento
        private void UpdateData()
        {
            // Check if data still exists.
            if (!File.Exists (this.DataPath))
            {
                throw new Exception (string.Format (Strings.Exception.MediaSaveData, this._id));
            }

            // Make sure data is in the right place.
            string currentdatapath = this.DataPath;
            this._currentstatus = this._status;

            if (currentdatapath != this.DataPath)
            {
                FileInfo file = new FileInfo (currentdatapath);
                file.MoveTo (this.DataPath);
            }

            // Remove old symlink if needed.
            if (this._currentstatus == SorentoLib.Enums.MediaStatus.Public || this._currentstatus == SorentoLib.Enums.MediaStatus.PublicTemporary)
            {
                if (this._currentpath != string.Empty)
                {
                    File.Delete (Services.Config.Get<string> (Enums.ConfigKey.path_publicmedia) + this._currentpath);
                }
            }

            // Create new symlink if needed.
            if (this._status == SorentoLib.Enums.MediaStatus.Public || this._status == SorentoLib.Enums.MediaStatus.PublicTemporary)
            {
                // Check if path exists, if not create it.
                if (!Directory.Exists (Services.Config.Get<string> (Enums.ConfigKey.path_publicmedia) + System.IO.Path.GetDirectoryName (this._path)))
                {
                    Directory.CreateDirectory (Services.Config.Get<string> (Enums.ConfigKey.path_publicmedia) + System.IO.Path.GetDirectoryName (this._path));
                }

                // Create a new symlink.
                UnixFileInfo unixfileinfo = new UnixFileInfo (this.DataPath);
                unixfileinfo.CreateSymbolicLink (Services.Config.Get<string> (Enums.ConfigKey.path_publicmedia) + this._path);
            }

            // Check if size changed.
            FileInfo fileinfo = new FileInfo (this.DataPath);
            this._size = fileinfo.Length;

            this._currentpath = this._path;
            this._currentstatus = this._status;
        }
コード例 #8
0
ファイル: IO.cs プロジェクト: sundowndk/SNDK
 public static void CreateSymlink(string SourcePath, string DestinationPath)
 {
     UnixFileInfo fileinfo = new UnixFileInfo (SourcePath);
     fileinfo.CreateSymbolicLink (DestinationPath);
 }
コード例 #9
0
ファイル: Runtime.cs プロジェクト: sundowndk/qnax
        public static void Initialize()
        {
            SetDefaults ();

            qnaxLib.Runtime.DBConnection = new Connection
                (
                    SNDK.Enums.DatabaseConnector.Mysql,
                    SorentoLib.Services.Config.Get<string> (qnax.Enums.ConfigKey.qnax_dbhostname),
                    SorentoLib.Services.Config.Get<string> (qnax.Enums.ConfigKey.qnax_dbdatabase),
                    SorentoLib.Services.Config.Get<string> (qnax.Enums.ConfigKey.qnax_dbusername),
                    SorentoLib.Services.Config.Get<string> (qnax.Enums.ConfigKey.qnax_dbpassword),
                    true
                );

            qnaxLib.Runtime.C5Connection = new Connection
                (
                    SNDK.Enums.DatabaseConnector.Mssql,
                    SorentoLib.Services.Config.Get<string> (qnax.Enums.ConfigKey.qnax_c5hostname),
                    SorentoLib.Services.Config.Get<string> (qnax.Enums.ConfigKey.qnax_c5database),
                    SorentoLib.Services.Config.Get<string> (qnax.Enums.ConfigKey.qnax_c5username),
                    SorentoLib.Services.Config.Get<string> (qnax.Enums.ConfigKey.qnax_c5password),
                    true
                );

            if (!Directory.Exists (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_html) + SorentoLib.Services.Config.Get<string> (Enums.ConfigKey.qnax_url)))
            {
                UnixFileInfo dirinfo = new UnixFileInfo (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_addins) + "qnax/data/html");
                dirinfo.CreateSymbolicLink (SorentoLib.Services.Config.Get<string> (SorentoLib.Enums.ConfigKey.path_html) + Path.GetDirectoryName (SorentoLib.Services.Config.Get<string> (Enums.ConfigKey.qnax_url)));
            }
        }