/// <summary>
        /// Get directory items and set them to obs collection
        /// </summary>
        /// <param name="root">Directory full path</param>
        private async void GetDir(string root)
        {
            try {
                if (File.Exists(root))
                {
                    DirectoryList.SelectedItem = null;
                    return;
                }
                currentDirectory = new DirectoryInfo(root);
                DirList          = DirList ?? new ObservableCollection <DirectoryItem>();
                DirList.Clear();
                // if name of folder is '0' set it as 'emulated/0'
                CurrFolderNameInfo = currentDirectory.Name == "0" ? Path.Combine(currentDirectory.Parent.Name, currentDirectory.Name) : currentDirectory.Name;
                CurrFolderPathInfo = currentDirectory.GetFileSystemInfoFullName();

                await Task.Run(() => {
                    Utilites.SetDirectoriesToList(currentDirectory, DirList);
                    foreach (var item in DirList)
                    {
                        item.PropertyChanged += ItemChecked_PropertyChanged;
                    }
                });
            } catch (Exception ex) {
                return;
            }
        }
Beispiel #2
0
        private void viewServer_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            string   path;
            TreeNode node;

            try
            {
                e.Node.Nodes.Clear();
                path = e.Node.FullPath;
                DirInfo dirInfo = new DirInfo(path);
                dirInfo.Type = (int)PacketType.ReqDirList;
                Packet.Serialize(dirInfo).CopyTo(this.sendBuf, 0);
                this.Send();

                Recv();
                DirList dirList = (DirList)Packet.Deserialize(this.recvBuf);

                foreach (string dir in dirList.dirList)
                {
                    node = e.Node.Nodes.Add(dir);
                    node.Nodes.Add("");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /*----< used for debugging >-----------------------------------*/

        /*
         *  Not needed for server application processing
         */
        bool testComponent()
        {
            //MessageDispatcher dispatcher = new MessageDispatcher();
            string remoteUrl = "http://localhost:8080/IPluggableComm";
            string localUrl  = "http://localhost:8081/IPluggableComm";

            Msg inMsg1 = new Msg(Msg.MessageType.request);

            inMsg1.command = Msg.Command.getCategories;
            inMsg1.to      = remoteUrl;
            inMsg1.from    = localUrl;
            Func <Msg, Msg> action1 = (Msg msg) =>
            {
                DirList dirList   = getCategories();
                Msg     returnMsg = new Msg(Msg.MessageType.reply);
                returnMsg.to   = msg.from;
                returnMsg.from = msg.to;
                foreach (DirName cat in dirList)
                {
                    returnMsg.arguments.Add(cat);
                }
                returnMsg.command = msg.command;
                return(returnMsg);
            };

            dispatcher_.addCommand(inMsg1.command, action1);

            Msg inMsg2 = new Msg(Msg.MessageType.request);

            inMsg2.to       = remoteUrl;
            inMsg2.from     = localUrl;
            inMsg2.command  = Msg.Command.getFiles;
            inMsg2.argument = "project";
            Func <Msg, Msg> action2 = (Msg msg) =>
            {
                FileList fileList  = getFiles(msg.argument);
                Msg      returnMsg = new Msg(Msg.MessageType.reply);
                returnMsg.to        = msg.from;
                returnMsg.from      = msg.to;
                returnMsg.argument  = msg.argument;
                returnMsg.arguments = fileList;
                returnMsg.command   = msg.command;
                return(returnMsg);
            };

            dispatcher_.addCommand(inMsg2.command, action2);

            Msg replyMsg1 = dispatcher_.doCommand(inMsg1.command, inMsg1);

            replyMsg1.show();
            comm_.postMessage(replyMsg1);

            Msg replyMsg2 = dispatcher_.doCommand(inMsg2.command, inMsg2);

            replyMsg2.show(false);
            comm_.postMessage(replyMsg2);

            return(true);
        }
 private void ItemChecked_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     BtnTransfer.TextColor = DirList.Any(x => x.ItemChecked) ? DarkTheme.themeColors["PrimaryTextColor"] : DarkTheme.themeColors["DisabledTextColor"];
     BtnCopy.TextColor     = DirList.Any(x => x.ItemChecked) ? DarkTheme.themeColors["PrimaryTextColor"] : DarkTheme.themeColors["DisabledTextColor"];
     BtnRemove.TextColor   = DirList.Any(x => x.ItemChecked) ? DarkTheme.themeColors["PrimaryTextColor"] : DarkTheme.themeColors["DisabledTextColor"];
     BtnRename.TextColor   = (DirList.All(x => x.ItemChecked) || DirList.Where(x => x.ItemChecked).Count() > 1) ? DarkTheme.themeColors["DisabledTextColor"] : DirList.Any(x => x.ItemChecked) ? DarkTheme.themeColors["PrimaryTextColor"] : DarkTheme.themeColors["DisabledTextColor"];
     BtnInfo.TextColor     = (DirList.All(x => x.ItemChecked) || DirList.Where(x => x.ItemChecked).Count() > 1) ? DarkTheme.themeColors["DisabledTextColor"] : DirList.Any(x => x.ItemChecked) ? DarkTheme.themeColors["PrimaryTextColor"] : DarkTheme.themeColors["DisabledTextColor"];
 }
 private async void BtnRemove_Clicked(object sender, EventArgs e)
 {
     if (DirList.Where(x => x.ItemChecked).Count() == 0)
     {
         return;
     }
     if (currentDirectory.Name == "storage")
     {
         ShowErrorMessage("Can't remove this directory");
         return;
     }
     try {
         var list = DirList.Where(x => x.ItemChecked);
         ModalBackGroundShown     = true;
         ActivityIndicatorShown   = true;
         ActivityIndicatorMessage = $"Deleted - 0/{list.Count()}";
         await Task.Run(() => {
             var i = 0;
             foreach (var item in list)
             {
                 try {
                     if (item.IsFolder)
                     {
                         if (!Directory.Exists(item.FullPath))
                         {
                             ShowErrorMessage($"Error! {item.FullPath} is not exist");
                             continue;
                         }
                         Directory.Delete(item.FullPath, true);
                     }
                     else
                     {
                         if (!File.Exists(item.FullPath))
                         {
                             ShowErrorMessage($"Error! {item.FullPath} is not exist");
                             continue;
                         }
                         File.Delete(item.FullPath);
                     }
                     i++;
                     ActivityIndicatorMessage = $"Deleted - {i}/{list.Count()}";
                 } catch (Exception ex) { }
             }
             GetDir(currentDirectory.GetFileSystemInfoFullName());
         }).ContinueWith((arg) => {
             ModalBackGroundShown     = false;
             ActivityIndicatorShown   = false;
             ActivityIndicatorMessage = "";
         });
     } catch (Exception ex) { }
 }
Beispiel #6
0
 public void RemoveDir(MarkDownDir dir)
 {
     if (dir != null)
     {
         for (int i = 0; i < DirList.Count; i++)
         {
             if (DirList[i].FullPath == dir.FullPath)
             {
                 DirList.RemoveAt(i);
                 break;
             }
         }
     }
 }
        private void BtnInfo_Clicked(object sender, EventArgs e)
        {
            if (DirList.Where(x => x.ItemChecked).Count() != 1)
            {
                return;
            }
            var item = DirList.FirstOrDefault(x => x.ItemChecked);

            if (item.IsFolder)
            {
                item.FormattedSize = Utilites.SizeSuffix(Utilites.SizeOfDirectory(item.FullPath), 2);
            }
            InfoDirModalWindow.BindingContext = item;
            SetInfoDirWindowUi(true);
        }
 private void BtnCopy_Clicked(object sender, EventArgs e)
 {
     if (DirList.Where(x => x.ItemChecked).Count() == 0)
     {
         return;
     }
     if (currentDirectory.Name == "storage")
     {
         ShowErrorMessage("Can't copy this directory");
         return;
     }
     IsCopyMode = true;
     ItemsForTransfer.Clear();
     ItemsForTransfer.AddRange(DirList.Where(x => x.ItemChecked));
     SetTransferUi(true);
 }
Beispiel #9
0
        private void SendSubDirList(string dir)
        {
            DirectoryInfo dirInfo = new DirectoryInfo(dir);

            DirectoryInfo[] diArr = dirInfo.GetDirectories();
            string[]        list  = new string[diArr.Length];
            int             i     = 0;

            foreach (DirectoryInfo di in diArr)
            {
                list[i++] = di.Name;
            }
            DirList dirList = new DirList(list);

            Packet.Serialize(dirList).CopyTo(this.sendBuf, 0);
            this.Send();
        }
Beispiel #10
0
    // Searchs for the passed string in the type names of all
    // assemblies in the specified paths.
    public void Search(String theSearchString)
    {
        //
        // Search the directory where mscorlib is located.
        //
        Assembly testAssy = Assembly.Load("mscorlib.dll");

        myVerboseWriter.WriteLine("Searching BCL");
        String dirFrameworks = Path.GetDirectoryName(testAssy.Location);

        ArrayList l = new ArrayList();

        BuildDLLFileList(dirFrameworks, l);
        for (int j = 0; j < l.Count; j++)
        {
            Search(theSearchString, (String)l[j]);
        }

        //
        // Search the current directory
        //
        myVerboseWriter.WriteLine("Searching the current directory...");
        l = new ArrayList();
        BuildDLLFileList(".", l);
        for (int j = 0; j < l.Count; j++)
        {
            Search(theSearchString, (String)l[j]);
        }

        //
        // Search the specified directories
        //
        Object[] dir = DirList.ToArray();
        for (int i = 0; i < dir.Length; i++)
        {
            myVerboseWriter.WriteLine("Searching directory  {0}...", dir[i]);

            l = new ArrayList();
            BuildDLLFileList((String)dir[i], l);

            for (int j = 0; j < l.Count; j++)
            {
                Search(theSearchString, (String)l[j]);
            }
        }
    }
 private void BtnRename_Clicked(object sender, EventArgs e)
 {
     if (DirList.Where(x => x.ItemChecked).Count() != 1)
     {
         return;
     }
     if (currentDirectory.Name == "storage")
     {
         ShowErrorMessage("Can't rename this directory");
         return;
     }
     AddDirModalWinShown = !AddDirModalWinShown;
     if (AddDirModalWinShown)
     {
         SetRenameDirectoryUi(true, DirList.FirstOrDefault(x => x.ItemChecked)?.Name);
     }
 }
Beispiel #12
0
        // Searchs for the passed string in the type names of all
        // .NET Framework assemblies and all DLLs in the specified paths.
        public void Search(String theSearchString)
        {
            //
            // Search the .NET Framework Directory
            //
            Assembly testAssy = typeof(object).Assembly;

            myVerboseWriter.WriteLine("Searching System Libraries");

            String    dirFrameworks = Path.GetDirectoryName(testAssy.Location);
            ArrayList l             = new ArrayList();

            BuildDLLFileList(dirFrameworks, l);
            for (int j = 0; j < l.Count; j++)
            {
                Search(theSearchString, (String)l[j]);
            }

            //
            // Search the current directory
            //
            myVerboseWriter.WriteLine("Searching the current directory...");
            l = new ArrayList();
            BuildDLLFileList(".", l);
            for (int j = 0; j < l.Count; j++)
            {
                Search(theSearchString, (String)l[j]);
            }

            //
            // Search the specified directories
            //
            Object[] dir = DirList.ToArray();

            for (int i = 0; i < dir.Length; i++)
            {
                myVerboseWriter.WriteLine("Searching directory  {0}...", dir[i]);
                l = new ArrayList();
                BuildDLLFileList((String)dir[i], l);
                for (int j = 0; j < l.Count; j++)
                {
                    Search(theSearchString, (String)l[j]);
                }
            }
        }
        /*----< returns names of folders in storagePath >--------------*/

        public static DirList getCategories()
        {
            DirList cats = new DirList();

            try
            {
                cats = System.IO.Directory.GetDirectories(ServerEnvironment.storagePath).ToList <string>();
                for (int i = 0; i < cats.Count; ++i)
                {
                    cats[i] = System.IO.Path.GetFileName(cats[i]);
                }
                return(cats);
            }
            catch
            {
                return(cats);
            }
        }
Beispiel #14
0
        private void viewServer_BeforeSelect(object sender, TreeViewCancelEventArgs e)
        {
            string       path = e.Node.FullPath;
            ListViewItem item;

            listServer.Items.Clear();

            try
            {
                DirInfo dirInfo = new DirInfo(path);
                dirInfo.Type = (int)PacketType.ReqDirList;
                Packet.Serialize(dirInfo).CopyTo(this.sendBuf, 0);
                this.Send();

                Recv();
                DirList dirList = (DirList)Packet.Deserialize(this.recvBuf);

                foreach (string dir in dirList.dirList)
                {
                    item            = listServer.Items.Add(dir);
                    item.ImageIndex = 1;
                    item.Tag        = "D";
                }

                dirInfo.Type = (int)PacketType.ReqFileList;
                Packet.Serialize(dirInfo).CopyTo(this.sendBuf, 0);
                this.Send();

                Recv();
                FileList fileList = (FileList)Packet.Deserialize(this.recvBuf);
                foreach (FileMeta meta in fileList.fileList)
                {
                    item = listServer.Items.Add(meta.fileName);
                    item.SubItems.Add(meta.fileLength.ToString());
                    item.SubItems.Add(meta.lastModified);
                    item.ImageIndex = 2;
                    item.Tag        = "F";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Beispiel #15
0
        private void PopulateServerTreeView()
        {
            TreeNode root = new TreeNode(caseName);

            root.Tag        = "C";
            root.ImageIndex = 0;

            Recv();
            DirList dirList = (DirList)Packet.Deserialize(this.recvBuf);

            foreach (string dir in dirList.dirList)
            {
                TreeNode subNode = new TreeNode(dir);
                subNode.Tag = "D";
                root.Nodes.Add(subNode);
            }
            viewServer.Nodes.Add(root);
            viewServer.SelectedNode = root;
        }
Beispiel #16
0
    // Searchs for the passed string in the type names of all
    // assemblies in the specified paths.
    public void Search(String theSearchString)
    {
        //
        // Search the directory where mscorlib is located.
        //
        myVerboseWriter.WriteLine("Searching BCL");

        ArrayList l = new ArrayList();

        BuildDLLFileList(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), l);
        for (int j = 0; j < l.Count; j++)
        {
            Search(theSearchString, (String)l[j]);
        }

        //
        // Search the current directory
        //
        myVerboseWriter.WriteLine("Searching the current directory...");
        l = new ArrayList();
        BuildDLLFileList(".", l);
        for (int j = 0; j < l.Count; j++)
        {
            Search(theSearchString, (String)l[j]);
        }

        //
        // Search the specified directories
        //
        Object[] dir = DirList.ToArray();
        for (int i = 0; i < dir.Length; i++)
        {
            myVerboseWriter.WriteLine("Searching directory  {0}...", dir[i]);

            l = new ArrayList();
            BuildDLLFileList((String)dir[i], l);

            for (int j = 0; j < l.Count; j++)
            {
                Search(theSearchString, (String)l[j]);
            }
        }
    }
Beispiel #17
0
        public void AddDir(MarkDownDir dir)
        {
            bool hasAdd = false;

            for (int i = 0; i < DirList.Count; i++)
            {
                if (DirList[i].FullPath == dir.FullPath)
                {
                    DirList.RemoveAt(i);
                    DirList.Insert(i, dir);
                    hasAdd = true;
                    break;
                }
            }
            if (!hasAdd)
            {
                DirList.Add(dir);
            }
        }
        private async void EntrySearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            List <FileSystemInfo> baseStors    = null;
            List <FileSystemInfo> foundedItems = null;

            CurrFolderPathInfo = "Founded - 0";
            var searchText = "";

            try {
                DirList.Clear();
                if (!string.IsNullOrEmpty(e.NewTextValue) || !string.IsNullOrWhiteSpace(e.NewTextValue))
                {
                    searchText   = e.NewTextValue.Trim().ToLower();
                    baseStors    = new List <FileSystemInfo>();
                    foundedItems = new List <FileSystemInfo>();
                    // get storage folders, this allow to skip 'self directory'
                    baseStors.AddRange(new DirectoryInfo("/storage").GetFileSystemInfos());
                    await Task.Run(() => {
                        foreach (var item in baseStors)
                        {
                            if (item.Name == "self")
                            {
                                continue;
                            }
                            // search all entries by full path and then skipping elements, witch names that don't match
                            foreach (var elem in Utilites.SearchAccessibleDirectoryItemsByFullName(item.GetFileSystemInfoFullName(), searchText).Distinct())
                            {
                                if (elem.Split('/').Last().ToLower().Contains(searchText))
                                {
                                    foundedItems.Add(elem.Split('.').Count() > 1 ? new FileInfo(elem) as FileSystemInfo : new DirectoryInfo(elem));
                                }
                            }
                        }
                        Utilites.FillDirsCollectionByItems(foundedItems, DirList, true);

                        CurrFolderPathInfo = $"Founded - {DirList.Count()}";
                    });
                }
            } catch (Exception ex) { }
        }
        private async void BtnAcceptNewDirAdding_Clicked(object sender, EventArgs e)
        {
            var newDirName = "";

            if (string.IsNullOrEmpty(EntryNewDirectoryField.Text) || string.IsNullOrWhiteSpace(EntryNewDirectoryField.Text))
            {
                return;
            }
            try {
                newDirName = Path.Combine(currentDirectory.FullName, EntryNewDirectoryField.Text.Trim());
                if (Directory.Exists(newDirName))
                {
                    ShowErrorMessage($"Folder: [{newDirName}] already exist!");
                    return;
                }
                if (RenameWindowShown)
                {
                    await Task.Run(() => Utilites.RenameDirItem(DirList.FirstOrDefault(x => x.ItemChecked)?.FullPath, newDirName)).ContinueWith((arg) => {
                        if (!arg.Result)
                        {
                            ShowErrorMessage($"Something goes wrong");
                        }
                    });
                }
                else
                {
                    // Try to create the directory.
                    DirectoryInfo di = Directory.CreateDirectory(newDirName);
                }
                GetDir(currentDirectory.GetFileSystemInfoFullName());

                EntryNewDirectoryField.Unfocus();
                EntryNewDirectoryField.Text = "";
                ModalBackGroundShown        = false;
                AddDirModalWinShown         = false;
            } catch (Exception ex) { }
        }
Beispiel #20
0
    /// Return a list of files & Directories from the file system.
    public void GetDirList(DirList dl)
    {
        Socket cSocket;
        int    bytes;
        char   seperator = Convert.ToChar("\n");

        string[] mess;

        m_sMes = "";

        /// Check to see if you are logged on to the FTP server.

        if (!m_bLoggedIn)
        {
            Login();
        }

        cSocket = CreateDataSocket();
        /// Send an FTP command.
        SendCommand("LIST -AL");

        if (!(m_iRetValue == 150 || m_iRetValue == 125))
        {
            MessageString = m_sReply;
            throw new IOException(m_sReply.Substring(4));
        }

        m_sMes = "";

        while (true)
        {
            Array.Clear(m_aBuffer, 0, m_aBuffer.Length);
            bytes   = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0);
            m_sMes += ASCII.GetString(m_aBuffer, 0, bytes);

            if (bytes < m_aBuffer.Length)
            {
                break;
            }
            System.Threading.Thread.Sleep(10);
        }

        mess = m_sMes.Split(seperator);
        cSocket.Close();
        ReadReply();

        if (m_iRetValue != 226)
        {
            MessageString = m_sReply;
            throw new IOException(m_sReply.Substring(4));
        }

        if (mess.Length > 0)
        {
            foreach (string tmpstr in mess)
            {
                if (tmpstr != "")
                {
                    DirFile lf;

                    SplitLine sl = ParseLine(tmpstr);

                    if (sl.Valid)
                    {
                        if (sl.Dir)
                        {
                            lf = new DirFile(sl.FileName, sl.FileDate, sl.FileTime, true, 0);
                        }
                        else
                        {
                            lf = new DirFile(sl.FileName, sl.FileDate, sl.FileTime, false, sl.FileSize);
                        }
                        dl.Add(lf);
                    }
                }
            }
        }
    }
Beispiel #21
0
        /// <summary>
        /// main entry point
        /// </summary>
        /// <param name="args">Arguments</param>
        /// <returns>some sort of weird exit code</returns>
        static int Main(string[] args)
        {
#if DEBUG
            //while debugging we supply fake arguments matching our serial port
            //args is different from C++ "argv", as it does not contains the
            //executable call itself, so a length of 0 means 0 arguments.
            if (args.Length == 0)
            {
                args = new string[] { "COM3,9600,8,1,n,n" };
                //args = new string[] { "net.cs" };
            }
#endif
            SerialOptions SO = parseParams(args);

            if (SO.valid)
            {
                SerialPort SP = new SerialPort(SO.Portname, SO.Baudrate, SO.Parity, SO.Databits, SO.Stopbits);
                SP.Handshake = SO.Handshake;
                SP.NewLine   = "\r"; //VT100 return key is '\r'
                SP.Open();
                VTconsole C = new VTconsole(SP);

                if (C.State != VTconsole.TerminalState.Ready)
                {
                    Console.WriteLine("Waiting for terminal ready on {0}...", SO.Portname);
                    while (C.State != VTconsole.TerminalState.Ready)
                    {
                        if (consoleExit())
                        {
                            return(1);
                        }
                        Thread.Sleep(2000);
                    }
                    Console.WriteLine("Terminal ready");
                }

                IPlugin P = null;

                if (File.Exists("INIT.cs") || File.Exists("INIT.dll"))
                {
                    Console.WriteLine("Found 'INIT' Plugin. Loading external plugin...");
                    try
                    {
                        P = File.Exists("INIT.cs") ? PluginManager.LoadPlugin("INIT.cs") : PluginManager.LoadPluginLib("INIT.dll");
                        if (P == null)
                        {
                            throw new Exception("Cannot run INIT Plugin, see errors below");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Loading failed.\r\nError: {0}", ex.Message);
                    }
                    if (P == null)
                    {
                        if (PluginManager.LastErrors != null)
                        {
                            foreach (CompilerError EE in PluginManager.LastErrors)
                            {
                                C.WriteLine("[{0};{1}] {2} {3}", EE.Line, EE.Column, EE.ErrorNumber, EE.ErrorText);
                            }
                        }
                        Console.WriteLine("Defaulting to main plugin...");
                        P = new DirList();
                    }
                }
                else
                {
                    Console.WriteLine("Starting main Plugin...");
                    P = new DirList();
                }
                P.Start(C);

                while (!consoleExit() && P.IsRunning)
                {
                    Thread.Sleep(500);
                }
                P.Stop();

                C.Clear();
                SP.Close();

                Console.WriteLine("Application terminated");
            }
            else
            {
                if (args.Length > 0 && File.Exists(args[0]))
                {
                    try
                    {
                        PluginManager.Compile(File.ReadAllText(args[0]), args[0].Substring(0, args[0].LastIndexOf('.')) + ".dll");
                        Console.WriteLine("File compiled");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Error compiling {0}.\r\n{1}", args[0], ex.Message);
                    }
                }
                else
                {
                    help();
                }
            }
            return(0);
        }
        private async void ButtonSearch_CheckAll_Accept_Clicked(object sender, EventArgs e)
        {
            if (IsTransferMode || IsCopyMode)
            {
                ModalBackGroundShown     = true;
                ActivityIndicatorShown   = true;
                ActivityIndicatorMessage = $"Processed - 0/{ItemsForTransfer.Count()}";

                // start operation
                await Task.Run(() => {
                    var i = 0;
                    foreach (var item in ItemsForTransfer)
                    {
                        if (currentDirectory.FullName.Contains(item.FullPath))
                        {
                            ShowErrorMessage($"This is a child folder of {item.Name}");
                            return(false);
                        }
                        Utilites.MoveCopyDirItem(item.FullPath, Path.Combine(currentDirectory.FullName, item.Name), IsCopyMode);
                        i++;
                        ActivityIndicatorMessage = $"Processed - {i}/{ItemsForTransfer.Count()}";
                    }
                    return(true);
                }).ContinueWith((arg) => {
                    if (!arg.Result)
                    {
                        return;
                    }
                    foreach (var item in DirList)
                    {
                        item.ItemChecked = isAllChecked;
                    }
                    GetDir(currentDirectory.GetFileSystemInfoFullName());
                }).ContinueWith((arg) => {
                    ModalBackGroundShown     = false;
                    ActivityIndicatorShown   = false;
                    ActivityIndicatorMessage = "";
                });

                SetTransferUi(false);
                return;
            }
            if (MenuShown)
            {
                isAllChecked = !isAllChecked;
                await Task.Run(() => {
                    foreach (var item in DirList)
                    {
                        item.ItemChecked = isAllChecked;
                    }
                });
            }
            else
            {
                isSearchShown = !isSearchShown;
                SetSearchUi(isSearchShown);
                if (isSearchShown)
                {
                    DirList.Clear();
                    // little hack for android
                    await Task.Run(() => {
                        Task.Delay(200).ContinueWith((args) => EntrySearchField.Focus());
                    });
                }
                else
                {
                    GetDir(currentDirectory.GetFileSystemInfoFullName());
                }
            }
        }
        /*----< here server responses to messages are defined >--------*/

        void initializeDispatcher()
        {
            // doTest
            Func <Msg, Msg> action1 = (Msg msg) =>
            {
                testComponent();
                Msg returnMsg = new Msg(Msg.MessageType.noReply);
                returnMsg.to      = msg.from;
                returnMsg.from    = msg.to;
                returnMsg.command = msg.command;
                return(returnMsg);
            };

            dispatcher_.addCommand(Msg.Command.doTest, action1);

            // getCategories
            Func <Msg, Msg> action2 = (Msg msg) =>
            {
                DirList dirList   = getCategories();
                Msg     returnMsg = new Msg(Msg.MessageType.reply);
                returnMsg.to       = msg.from;
                returnMsg.from     = msg.to;
                returnMsg.argument = msg.argument;
                foreach (DirName cat in dirList)
                {
                    returnMsg.arguments.Add(cat);
                }
                returnMsg.command = msg.command;
                return(returnMsg);
            };

            dispatcher_.addCommand(Msg.Command.getCategories, action2);

            // getFiles
            Func <Msg, Msg> action3 = (Msg msg) =>
            {
                FileList fileList  = getFiles(msg.argument);
                Msg      returnMsg = new Msg(Msg.MessageType.reply);
                returnMsg.to       = msg.from;
                returnMsg.from     = msg.to;
                returnMsg.argument = msg.argument;
                foreach (FileName file in fileList)
                {
                    returnMsg.arguments.Add(file);
                }
                //returnMsg.arguments = fileList;
                returnMsg.command = msg.command;
                return(returnMsg);
            };

            dispatcher_.addCommand(Msg.Command.getFiles, action3);

            // synchLocal
            Func <Msg, Msg> action4 = (Msg msg) =>
            {
                string    synchPath = FileNameEditor.pathCombine(ServerEnvironment.storagePath, msg.argument);
                FileSynch fs        = new FileSynch(synchPath);
                fs.isSynched(msg.arguments);
                Msg replyMsg = new Msg(Msg.MessageType.reply);
                replyMsg.to       = msg.from;
                replyMsg.from     = msg.to;
                replyMsg.argument = msg.argument;
                foreach (string file in fs.notInList)
                {
                    replyMsg.arguments.Add(file);
                }
                replyMsg.command = msg.command;
                return(replyMsg);
            };

            dispatcher_.addCommand(Msg.Command.synchLocal, action4);

            // synchRemote
            Func <Msg, Msg> action5 = (Msg msg) =>
            {
                string    synchPath = FileNameEditor.pathCombine(ServerEnvironment.storagePath, msg.argument);
                FileSynch fs        = new FileSynch(synchPath);
                fs.isSynched(msg.arguments);
                Msg replyMsg = new Msg(Msg.MessageType.reply);
                replyMsg.to       = msg.from;
                replyMsg.from     = msg.to;
                replyMsg.argument = msg.argument;
                foreach (string file in fs.notInSyncDir)
                {
                    replyMsg.arguments.Add(file);
                }
                replyMsg.command = msg.command;
                return(replyMsg);
            };

            dispatcher_.addCommand(Msg.Command.synchRemote, action5);

            // sendFile
            Func <Msg, Msg> action6 = (Msg msg) =>
            {
                string fileRef  = msg.argument;
                string fileSpec = FileNameEditor.pathCombine(CommEnvironment.serverStoragePath, fileRef);
                fileSpec = System.IO.Path.GetFullPath(fileSpec);
                comm_.postFile(fileSpec);
                Msg replyMsg = new Msg(Msg.MessageType.noReply);
                replyMsg.to   = msg.from;
                replyMsg.from = msg.to;
                return(replyMsg);
            };

            dispatcher_.addCommand(Msg.Command.sendFile, action6);

            // acceptFile
            Func <Msg, Msg> action7 = (Msg msg) =>
            {
                comm_.sndr.setFileDestinationPath(ServerEnvironment.storagePath);
                //string fileRef = msg.argument;
                //string fileSpec = FileNameEditor.pathCombine(CommEnvironment.serverStoragePath, fileRef);
                //fileSpec = System.IO.Path.GetFullPath(fileSpec);
                //comm_.postFile(fileSpec);
                Msg replyMsg = new Msg(Msg.MessageType.noReply);
                replyMsg.to   = msg.from;
                replyMsg.from = msg.to;
                return(replyMsg);
            };

            dispatcher_.addCommand(Msg.Command.acceptFile, action7);
        }
Beispiel #24
0
    private void moveInput()
    {
        if (Input.GetKey(KeyCode.Q))
        {
            vecMove.x -= speed;
            MovingDir = DirList.Left;
        }
        else if (Input.GetKeyUp(KeyCode.Q))
        {
            vecMove.x -= 5f;
        }

        if (Input.GetKey(KeyCode.S))
        {
            vecMove.y -= speed;
            MovingDir = DirList.Down;
        }
        else if (Input.GetKeyUp(KeyCode.S))
        {
            vecMove.y += 5f;
        }

        if (Input.GetKey(KeyCode.Z))
        {
            vecMove.y += speed;
            MovingDir = DirList.Up;
        }
        else if (Input.GetKeyUp(KeyCode.Z))
        {
            vecMove.y += 5f;
        }

        if (Input.GetKey(KeyCode.D))
        {
            vecMove.x += speed;
            MovingDir = DirList.Right;
        }
        else if (Input.GetKeyUp(KeyCode.D))
        {
            vecMove.x += 5f;
        }

        if (Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.Q) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D))
        {
            FootSteps();
            PlayAnim("walk");
            Activity = ActiviList.Walking;
        }
        if (!Input.GetKey(KeyCode.Z) && !Input.GetKey(KeyCode.Q) && !Input.GetKey(KeyCode.S) && !Input.GetKey(KeyCode.D))
        {
            Activity = ActiviList.Static;
            PlayAnim("static");
            CancelInvoke("Foots");
            stepTriggered = false;
        }

        vecMove.x *= 0.1f;
        vecMove.y *= 0.1f;
    }
Beispiel #25
0
 // Add a directory to the search set
 public void DirAdd(string dir)
 {
     DirList.Add(dir);
 }
Beispiel #26
0
        //*************** Read IMD Directory
        public List <DirList> ReadImdDir(string diskFileName, ref long diskTotal)
        {
            // Check if file already in memory. If not, then process
            // open file: fileName
            // check H37 file type in byte 6
            // get disk parameters
            // Read directory gathering file names and sizes
            // update fcbList with fcb list for each file
            // add file names listBox2.Items
            // update file count and total file size
            var          sectorSizeList = new int[] { 128, 256, 512, 1024, 2048, 4096, 8192 }; // IMD values
            int          result         = 0;
            UTF8Encoding encoding       = new UTF8Encoding();

            if (diskFileName != DiskImageImdActive)                  // check if data already in memory
            {
                FileStream   file     = File.OpenRead(diskFileName); // read entire file into an array of byte
                BinaryReader fileByte = new BinaryReader(file);
                Int32        fileLen  = (int)file.Length;
                //byte[] buf = new byte[bufferSize];
                try
                {
                    if (fileByte.Read(buf, 0, bufferSize) != fileLen)
                    {
                        MessageBox.Show("IMD file read error", "Error", MessageBoxButtons.OK);
                        return(null);
                    }
                }
                catch
                {
                    MessageBox.Show("File buffer too small", "Error", MessageBoxButtons.OK);
                    return(null);
                }

                DiskImageImdActive = diskFileName;
                diskSize           = fileLen;
                fileNameList.Clear();
            }
            else
            {
                return(fileNameList);       // list is current do nothing
            }
            int bufPtr = 0, firstSector;

            while (buf[bufPtr] != 0x1a && bufPtr < bufferSize)
            {
                bufPtr++;                                   // look for end of text comment in IMD file
            }
            if (bufPtr < bufferSize && buf[bufPtr + 1] < 6) // process as IMD file
            {
                bufPtr += 4;
                var spt = buf[bufPtr++]; // sectors per track
                sectorSize = sectorSizeList[buf[bufPtr]];
                var skewMap = new int[spt];

                for (var i = 0; i < spt; i++)
                {
                    skewMap[i] = buf[++bufPtr];                           // load skewmap
                }
                firstSector = ++bufPtr;
                int ctr,
                //allocBlock = 0,
                //albNumSize = 1,
                    dirStart    = 0,
                    dirSizeD    = 0,
                    sptD        = 0,
                    sectorSizeD = 0,
                    numTrack    = 0;

                //
                // map sectors
                // bufPtr already points to first sector marker
                /**** use class variable for the following two variables ************/
                // var sectorMax = spt * 160;          // max number of tracks
                //var diskMap = new int[sectorMax];
                var sectorCnt = 0;
                //var filePtr = firstSector;
                while (sectorCnt < sectorMax)
                {
                    //int t1 = sectorCnt % spt;
                    //int t2 = skewMap[sectorCnt % spt];
                    //int t3 = (sectorCnt / spt) * spt;
                    diskMap[(sectorCnt / spt) * spt + skewMap[sectorCnt % spt] - 1] = bufPtr;         // bufPtr points to sector marker

                    // int t4 = buf[bufPtr];
                    switch (buf[bufPtr])
                    {
                    case 1:
                    case 3:
                    case 5:
                    case 7:
                        bufPtr += sectorSize + 1;
                        break;

                    case 2:
                    case 4:
                    case 6:
                    case 8:
                        bufPtr += 2;
                        break;

                    case 0:
                        bufPtr++;
                        break;

                    default:
                        MessageBox.Show("Error - IMD sector marker out of scope", "Error",
                                        MessageBoxButtons.OK);
                        break;
                    }

                    if (((sectorCnt + 1) % spt) == 0 && sectorCnt > 0)
                    {
                        bufPtr += 5 + spt;                                                    // skip track header and interleave info
                    }
                    sectorCnt++;
                }
                //

                var diskType = (int)buf[diskMap[0] + 6];


                for (ctr = 0; ctr < DiskType.GetLength(0); ctr++) // search DiskType array for values
                {
                    if (diskType == DiskType[ctr, 0])
                    {
                        albSize      = DiskType[ctr, 1]; // ALB Size
                        albNumSize   = DiskType[ctr, 3]; // size of ALB size in directory
                        dirStart     = DiskType[ctr, 2]; // physical start of directory
                        dirSizeD     = DiskType[ctr, 4]; // size of the directory
                        sptD         = DiskType[ctr, 6]; // sectors per track
                        sectorSizeD  = DiskType[ctr, 7]; // sector size
                        numTrack     = DiskType[ctr, 8];
                        diskSize     = diskTotal = numTrack * spt * sectorSize / 1024;
                        dirSectStart = dirStart / sectorSize;
                        break;
                    }
                }

                // error if no match found
                if (ctr == DiskType.GetLength(0))
                {
                    MessageBox.Show("Error - CP/M Disk Type not found in IMD File", "Error", MessageBoxButtons.OK);
                }
                else
                {
                    result = 1;
                }


                if ((spt != sptD || sectorSize != sectorSizeD) && result == 1)
                {
                    MessageBox.Show("Error - sector/track or sector size mismatch", "Error", MessageBoxButtons.OK);
                    result = 0;
                }

                if (result == 1) // done error checking, read directory
                {
                    // Read Dir
                    var diskUsed = 0;
                    for (var i = 0; i < dirSizeD / sectorSize; i++)
                    {
                        bufPtr = diskMap[(int)(dirStart / sectorSize) + i];
                        if (buf[bufPtr++] % 2 > 0)            // IMD sector marker is odd. data should contain sector size
                        {
                            for (var dirPtr = 0; dirPtr < sectorSize; dirPtr += 32)
                            {
                                if (buf[bufPtr + dirPtr] != 0xe5)
                                {
                                    var flagStr = "";
                                    if ((buf[bufPtr + dirPtr + 9] & 0x80) > 0)
                                    {
                                        flagStr += "R/O";
                                    }
                                    if ((buf[bufPtr + dirPtr + 10] & 0x80) > 0)
                                    {
                                        flagStr += " S";
                                    }
                                    if ((buf[bufPtr + dirPtr + 11] & 0x80) > 0)
                                    {
                                        flagStr += " W";
                                    }
                                    for (int k = 9; k < 12; k++)
                                    {
                                        buf[bufPtr + dirPtr + k] &= 0x7f;         // mask high bit for string conversion
                                    }
                                    string fnameStr = encoding.GetString(buf, bufPtr + dirPtr + 1, 11);
                                    //fnameStr = fnameStr.Insert(8, " ");
                                    int fileDirSize = buf[bufPtr + dirPtr + 15] * 128;
                                    var temp        = new DirList(fnameStr, fileDirSize, flagStr); // temp storage
                                    Array.Copy(buf, bufPtr + dirPtr + 1, temp.fnameB, 0, 11);      // copy byte filename
                                    diskUsed       += fileDirSize;
                                    temp.fcbNumSize = albNumSize;
                                    var tempFcb = new FCBlist
                                    {
                                        extantnum = buf[bufPtr + dirPtr + 12],
                                        fcbnum    = buf[bufPtr + dirPtr + 15]
                                    };
                                    for (var k = 16; k < 32; k++)
                                    {
                                        tempFcb.fcb[k - 16] = (int)buf[bufPtr + dirPtr + 16 + ((k - 16) * albNumSize)];
                                    }
                                    temp.fcbList.Add(tempFcb);
                                    var obj = fileNameList.FirstOrDefault(x => x.fname == fnameStr);
                                    if (obj != null)              // directory entry exists
                                    {
                                        obj.fsize += fileDirSize; // update file size
                                        obj.fcbList.Add(tempFcb); // add file control block
                                    }
                                    else
                                    {
                                        fileNameList.Add(temp);
                                    }
                                }
                            }
                        }
                    }
                    fileNameList.Sort();
                    //debug
                    //foreach (var f in fileNameList)
                    //{
                    //    var testStr = f.fname + " ";
                    //    foreach (var t in f.fcbList)
                    //    {
                    //        for (var i = 0; i < 16/f.fcbNumSize; i++)
                    //            testStr = testStr + t.fcb[i].ToString() + " ";
                    //    }

                    //    Console.WriteLine(testStr);
                    //}
                }
            }

            if (result == 0)            // clear instance data
            {
                diskSize           = 0;
                DiskImageImdActive = "";
                fileNameList.Clear();
            }
            return(fileNameList);
        }
Beispiel #27
0
    /// Return a list of files & Directories from the file system.
    public void GetDirList(DirList dl)
    {
        Socket cSocket;
        int bytes;
        char seperator = Convert.ToChar("\n");
        string[] mess;

        m_sMes = "";

        /// Check to see if you are logged on to the FTP server.

        if (!m_bLoggedIn)
        {
            Login();
        }

        cSocket = CreateDataSocket();
        /// Send an FTP command.
        SendCommand("LIST -AL");

        if (!(m_iRetValue == 150 || m_iRetValue == 125))
        {
            MessageString = m_sReply;
            throw new IOException(m_sReply.Substring(4));
        }

        m_sMes = "";

        while (true)
        {
            Array.Clear(m_aBuffer, 0, m_aBuffer.Length);
            bytes = cSocket.Receive(m_aBuffer, m_aBuffer.Length, 0);
            m_sMes += ASCII.GetString(m_aBuffer, 0, bytes);

            if (bytes < m_aBuffer.Length)
            {
                break;
            }
            System.Threading.Thread.Sleep(10);
        }

        mess = m_sMes.Split(seperator);
        cSocket.Close();
        ReadReply();

        if (m_iRetValue != 226)
        {
            MessageString = m_sReply;
            throw new IOException(m_sReply.Substring(4));
        }

        if (mess.Length > 0)
        {
            foreach (string tmpstr in mess)
            {
                if (tmpstr != "")
                {
                    DirFile lf;

                    SplitLine sl = ParseLine(tmpstr);

                    if (sl.Valid)
                    {
                        if (sl.Dir)
                        {
                            lf = new DirFile(sl.FileName, sl.FileDate, sl.FileTime, true, 0);
                        }
                        else
                        {
                            lf = new DirFile(sl.FileName, sl.FileDate, sl.FileTime, false, sl.FileSize);
                        }
                        dl.Add(lf);
                    }
                }
            }
        }
    }