Exemplo n.º 1
0
        public void InitUnix()
        {
            //TODO: /tmp/.X1-lock
            //string lockFile = "/tmp/.X" + 1 + "-lock";

            string path = "/tmp/.X11-unix/X" + 1;

            UnixFileInfo ufi = new UnixFileInfo(path);

            UnixEndPoint ep = new UnixEndPoint(path);

            listener = new Socket(AddressFamily.Unix, SocketType.Stream, 0);

            //Bind creates the socket file right now
            listener.Bind(ep);
            //savedEP = listener.LocalEndPoint;

            //listen backlog 1 for now
            listener.Listen(1);

            Socket client = listener.Accept();

            listener.Shutdown(SocketShutdown.Both);
            listener.Close();
            ufi.Delete();
        }
Exemplo n.º 2
0
        public void Delete(SafeUri uri)
        {
            UnixFileInfo info = new UnixFileInfo(uri.LocalPath);

            info.Delete();
        }
        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;
        }