private void m_tmrRename_Tick(object sender, System.EventArgs e)
        {
            m_tmrRename.Stop();

            if (m_files.Count != 1)
            {
                return;
            }
            RscFileItemDesc it = m_files[0];

            RscPageArgsRet appInput = new RscPageArgsRet(m_AppArgs,
                                                         m_AppFrame.AppTitle, m_AppFrame.AppIconRes, "txRenameTo");

            appInput.SetFlag(0, it.strFileName);
            appInput.SetFlag(1, "NoEmpty");
            appInput.SetFlag(2, "FileName");
            appInput.SetFlag(3, "no history");
            appInput.SetData(0, it.strFileName);
            appInput.SetInput("RscDlg_TxtInputV10");

            this.NavigationService.Navigate(appInput.GetNavigateUri(csDlgsAssy));
        }
        private void ListFiles()
        {
            ActionPanel.Visibility = Rsc.Collapsed;

            //problems with txFilter_TextChanged!!

            /*
             * if( txFilter.Text.Length == 0 )
             *      txFilter.Text = "*.*";
             */

            RscFileItemDesc itCurrent;

            m_folders.Clear();
            m_files.Clear();

            itCurrent             = new RscFileItemDesc(m_AppFrame.Theme);
            itCurrent.bFolder     = true;
            itCurrent.bWalked     = false;
            itCurrent.strParent   = "";
            itCurrent.strFileName = m_txtRootFldr.Text;
            itCurrent.Parent      = m_folders;

            RscStore store = new RscStore();

            if (!store.FolderExists(itCurrent.Path))
            {
                itCurrent.bWalked   = true;
                itCurrent.LastError = "Not exist!";
            }

            m_folders.Add(itCurrent);

            m_AppFrame.SetStatusText("Listing files...");
            m_AppFrame.StartTimer("list files", LayoutRoot, 1, 0, true);
        }
        private void m_AppFrame_OnTimer_Sub1(object sender, RscAppFrameTimerEventArgs e)
        {
            switch (e.Reason)
            {
            case "copy move files_Cancel":
            {
                m_AppFrame.SetStatusText("User canceled operation!", StatusColoring.Error);
                break;
            }

            case "copy move files":
            {
                int iRootLen = m_txtRootFldr.Text.Length;

                if (e.Pos == 0)
                {
                    foreach (RscFileItemDesc itFldr in m_folders)
                    {
                        string sPart = itFldr.Path.Substring(iRootLen);
                        if (sPart.Length > 0)
                        {
                            string sNewFolder = m_sCopyMoveDest;
                            if (iRootLen == 0)
                            {
                                sNewFolder += "\\";
                            }
                            sNewFolder += sPart;

                            try
                            {
                                RscStore store = new RscStore();
                                store.CreateFolder(sNewFolder);
                            }
                            catch (Exception /*exc*/)
                            {
                                m_AppFrame.SetStatusText("ERR: Unable to copy folder stru near: " + sNewFolder, StatusColoring.Error);
                                e.Completed = true;
                                return;
                            }
                        }
                    }

                    e.Max = 1;
                }
                else
                {
                    RscFileItemDesc it = m_files[e.Pos - 1];

                    string sErr = "";
                    try
                    {
                        string sCopyMoveTo = m_sCopyMoveDest;
                        if (iRootLen == 0)
                        {
                            sCopyMoveTo += "\\";
                        }
                        sCopyMoveTo += it.Path.Substring(iRootLen);

                        RscStore store = new RscStore();

                        if (m_sCopyMove == "move")
                        {
                            store.MoveFileForce(it.Path, sCopyMoveTo);
                        }
                        else
                        {
                            store.CopyFileForce(it.Path, sCopyMoveTo);
                        }
                    }
                    catch (Exception exc)
                    {
                        sErr = "Unable to " + m_sCopyMove + " file.\r\n" + exc.Message;
                    }

                    if (sErr.Length == 0)
                    {
                        m_files.RemoveAt(e.Pos - 1);

                        if ((e.Pos - 1) < m_files.Count)
                        {
                            int iPos = e.Pos;
                            e.Pos = iPos;                                     //Denie subsys to increment...
                        }
                        else
                        {
                            e.Completed = true;
                        }
                    }
                    else
                    {
                        it.LastError = sErr;

                        //ReQuery...
                        lbFiles.ItemsSource = null;
                        lbFiles.ItemsSource = m_files;

                        if ((e.Pos - 1) < (m_files.Count - 1))
                        {
                            e.Max++;
                        }
                        else
                        {
                            e.Completed = true;
                        }
                    }

                    if (e.Completed)
                    {
                        if (m_sCopyMove == "move")
                        {
                            if (m_files.Count == 0)                                      //Otherwise error occured...
                            {
                                if (chbRecurse.IsChecked.Value)                          //Otherwise no sub-tree deletion...
                                {
                                    int iIdx = (m_folders.Count - 1) + 1;
                                    for (;;)
                                    {
                                        iIdx--;
                                        if (iIdx < 0)
                                        {
                                            break;
                                        }

                                        try
                                        {
                                            if (m_folders[iIdx].Path.Substring(iRootLen).Length > 0)
                                            {
                                                RscStore store = new RscStore();
                                                store.DeleteFolder(m_folders[iIdx].Path);
                                            }

                                            m_folders.RemoveAt(iIdx);
                                        }
                                        catch (Exception /*exc*/)
                                        {
                                        }
                                    }
                                }
                            }

                            if (m_files.Count == 0)
                            {
                                m_AppFrame.SetStatusText("Move succeeded!", StatusColoring.Success);
                            }
                            else
                            {
                                m_AppFrame.SetStatusText("Move failed for some item(s)!", StatusColoring.Error);
                            }
                        }
                        else
                        {
                            if (m_files.Count == 0)
                            {
                                m_AppFrame.SetStatusText("Copy succeeded!", StatusColoring.Success);
                            }
                            else
                            {
                                m_AppFrame.SetStatusText("Copy failed for some item(s)!", StatusColoring.Error);
                            }
                        }

                        //Causes exception...
                        //ListFiles();

                        ActionPanel.Visibility = Rsc.Collapsed;
                    }
                }

                break;
            }

            case "delete files_Cancel":
            {
                m_AppFrame.SetStatusText("User canceled operation!", StatusColoring.Error);
                break;
            }

            case "delete files":
            {
                if (e.Pos >= m_files.Count)
                {
                    e.Completed = true;
                }
                else
                {
                    RscFileItemDesc it = m_files[e.Pos];

                    string sErr = "";
                    try
                    {
                        RscStore store = new RscStore();
                        store.DeleteFile(it.Path);
                    }
                    catch (Exception exc)
                    {
                        sErr = "Unable to delete file.\r\n" + exc.Message;
                    }

                    if (sErr.Length == 0)
                    {
                        m_files.RemoveAt(e.Pos);

                        if (e.Pos < m_files.Count)
                        {
                            int iPos = e.Pos;
                            e.Pos = iPos;                                     //Denie subsys to increment...
                        }
                        else
                        {
                            e.Completed = true;
                        }
                    }
                    else
                    {
                        it.LastError = sErr;

                        //ReQuery...
                        lbFiles.ItemsSource = null;
                        lbFiles.ItemsSource = m_files;

                        if (e.Pos < (m_files.Count - 1))
                        {
                            e.Max++;
                        }
                        else
                        {
                            e.Completed = true;
                        }
                    }
                }

                if (e.Completed)
                {
                    if (m_files.Count == 0)                              //Otherwise error occured...
                    {
                        if (chbRecurse.IsChecked.Value)                  //Otherwise no sub-tree deletion...
                        {
                            int iIdx = (m_folders.Count - 1) + 1;
                            for (;;)
                            {
                                iIdx--;
                                if (iIdx < 0)
                                {
                                    break;
                                }

                                try
                                {
                                    if (m_folders[iIdx].Path.Length > 0)
                                    {
                                        RscStore store = new RscStore();
                                        store.DeleteFolder(m_folders[iIdx].Path);
                                    }

                                    m_folders.RemoveAt(iIdx);
                                }
                                catch (Exception /*exc*/)
                                {
                                }
                            }
                        }
                    }

                    if (m_files.Count == 0)
                    {
                        m_AppFrame.SetStatusText("Delete succeeded!", StatusColoring.Success);

                        // //
                        //

                        if (m_sAutoOperation.Length > 0)
                        {
                            if (m_iAutoOpPath + 1 < m_asAutoOpPathes.Length)
                            {
                                m_iAutoOpPath++;
                                m_txtRootFldr.Text = m_asAutoOpPathes[m_iAutoOpPath];
                                m_AppFrame.AutoClick(m_btnCycle, new System.Windows.RoutedEventHandler(m_btnCycle_Click));
                            }
                            else
                            {
                                PrepareExit();
                                NavigationService.GoBack();
                            }
                        }

                        //
                        // //
                    }
                    else
                    {
                        m_AppFrame.SetStatusText("Delete failed for some item(s)!", StatusColoring.Error);
                    }

                    //Causes exception...
                    //ListFiles();

                    ActionPanel.Visibility = Rsc.Collapsed;
                }

                break;
            }
            }
        }
        private void m_AppFrame_OnTimer(object sender, RscAppFrameTimerEventArgs e)
        {
            switch (e.Reason)
            {
            case "list files_Cancel":
            {
                m_folders.Clear();
                m_files.Clear();
                m_AppFrame.SetStatusText("User canceled operation!", StatusColoring.Error);
                break;
            }

            case "list files":
            {
                string sFileFilter = txFilter.Text;
                if (sFileFilter.Length == 0)
                {
                    sFileFilter = "*.*";
                }
                sFileFilter = sFileFilter.Replace("\\", "");
                sFileFilter = sFileFilter.Replace("/", "");
                sFileFilter = sFileFilter.Replace(":", "");
                sFileFilter = sFileFilter.Replace(('"').ToString(), "");
                sFileFilter = sFileFilter.Replace("<", "");
                sFileFilter = sFileFilter.Replace(">", "");
                sFileFilter = sFileFilter.Replace("|", "");

                RscFileItemDesc itCurrent;
                RscFileItemDesc it;

                RscStore store = new RscStore();

                itCurrent = m_folders[e.Pos];

                if (!itCurrent.bWalked)
                {
                    if (chbRecurse.IsChecked.Value)
                    {
                        string[] fldrs = RscSort.OrderBy(store.GetFolderNames(itCurrent.Path, "*.*", chbShowHidden.IsChecked.Value));
                        foreach (string node in fldrs)
                        {
                            it = new RscFileItemDesc(m_AppFrame.Theme);

                            it.bFolder = true;
                            it.bWalked = false;

                            it.strParent   = itCurrent.Path;
                            it.strFileName = node;

                            e.Max++;
                            it.Parent = m_folders;
                            m_folders.Add(it);
                        }
                    }

                    itCurrent.bWalked = true;

                    if (e.Pos == e.Max)
                    {
                        e.Pos = 0;
                    }
                }
                else
                {
                    if (itCurrent.LastError.Length == 0)                              //Otherwise Not Exist!!!
                    {
                        string[] fles = RscSort.OrderBy(store.GetFileNames(itCurrent.Path, sFileFilter, chbShowHidden.IsChecked.Value));
                        foreach (string node in fles)
                        {
                            it = new RscFileItemDesc(m_AppFrame.Theme);

                            it.bFolder = false;
                            it.bWalked = false;

                            it.strParent   = itCurrent.Path;
                            it.strFileName = node;

                            it.Parent = m_files;
                            m_files.Add(it);
                        }
                    }

                    if (e.Pos == e.Max)
                    {
                        //ReQuery...
                        lbFiles.ItemsSource = null;
                        lbFiles.ItemsSource = m_files;

                        btnRename.Visibility = Rsc.ConditionalVisibility(m_files.Count == 1 && m_folders.Count == 1);
                        imgRename.Visibility = btnRename.Visibility;
                        //
                        ActionPanel.Visibility = Rsc.ConditionalVisibility(
                            (m_files.Count > 0 || m_txtRootFldr.Text.Length > 0) && m_folders[0].LastError.Length == 0);
                        m_btnDelete.Visibility = Rsc.ConditionalVisibility(
                            (m_files.Count > 0 || m_folders.Count > 0 /*|| m_txtRootFldr.Text.Length > 0*/) && m_folders[0].LastError.Length == 0);
                        //
                        btnCopy.Visibility = Rsc.ConditionalVisibility(
                            (m_files.Count > 0 /*|| m_txtRootFldr.Text.Length > 0*/) && m_folders[0].LastError.Length == 0);
                        imgCopy.Visibility = btnCopy.Visibility;
                        //
                        btnMove.Visibility = Rsc.ConditionalVisibility(
                            (m_files.Count > 0 /*|| m_txtRootFldr.Text.Length > 0*/) && m_folders[0].LastError.Length == 0);
                        imgMove.Visibility = btnMove.Visibility;

                        m_AppFrame.SetStatusText(m_files.Count.ToString() + " file(s) in "
                                                 + m_folders.Count.ToString() + " folder(s) listed");

                        // //
                        //

                        if (m_sAutoOperation.Length > 0)
                        {
                            ActionPanel.Visibility = Rsc.Collapsed;

                            switch (m_sAutoOperation)
                            {
                            case "AutoDelete":
                                m_AppFrame.AutoClick(m_btnDelete, new System.Windows.RoutedEventHandler(m_btnDelete_Click));
                                break;
                            }
                        }

                        //
                        // //
                    }
                }

                break;
            }

            default:
                m_AppFrame_OnTimer_Sub1(sender, e);
                break;
            }
        }
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            if (m_AppArgs.Waiting)
            {
                RscPageArgsRet appOutput = m_AppArgs.GetOutput();
                if (appOutput != null)
                {
                    switch (appOutput.ID)
                    {
                    case "RootFldrPath":
                    {
                        if (appOutput.GetFlag(0) == "Ok")
                        {
                            m_txtRootFldr.Text = appOutput.GetData(0);
                            ListFiles();
                        }
                        else
                        {
                            //NOP...
                        }
                        break;
                    }

                    case "CopyMove":
                    {
                        if (appOutput.GetFlag(0) == "Ok")
                        {
                            m_sCopyMoveDest = appOutput.GetData(0);

                            if (chbRecurse.IsChecked.Value && (m_txtRootFldr.Text.Length == 0 || m_sCopyMoveDest.ToUpper().IndexOf(m_txtRootFldr.Text.ToUpper()) == 0))
                            {
                                MessageBox.Show("Unable to " + m_sCopyMove + " from parent folder to its' child folder.");
                            }
                            else
                            {
                                m_AppFrame.SetStatusText(m_sCopyMove + "...");
                                m_AppFrame.StartTimer("copy move files", LayoutRoot, 1, 0, true);
                            }
                        }
                        else
                        {
                            //NOP...
                        }
                        break;
                    }

                    case "txRenameTo":
                    {
                        if (appOutput.GetFlag(0) == "Ok")
                        {
                            RscFileItemDesc it = m_files[0];

                            string sNewName = appOutput.GetData(0);

                            if (it.strFileName.ToUpper().CompareTo(sNewName.ToUpper()) != 0)
                            {
                                RscStore store = new RscStore();

                                string sNewPath = it.strParent;
                                if (sNewPath.Length > 0)
                                {
                                    sNewPath += "\\";
                                }
                                sNewPath += sNewName;

                                if (store.FileExists(sNewPath))
                                {
                                    MessageBox.Show("Name already in use!\r\n\r\n" + sNewPath);
                                }
                                else
                                {
                                    if (RscStore.ExtensionOfPath(sNewPath).ToUpper().CompareTo(RscStore.ExtensionOfPath(it.Path).ToUpper()) != 0)
                                    {
                                        if (MessageBoxResult.OK != MessageBox.Show("Do you really want to change type from " + RscStore.ExtensionOfPath(it.Path)
                                                                                   + " to " + RscStore.ExtensionOfPath(sNewPath) + "?\r\n\r\n(press Back to cancel)"))
                                        {
                                            return;
                                        }
                                    }

                                    try
                                    {
                                        store.MoveFile(it.Path, sNewPath);
                                    }
                                    catch (Exception exc)
                                    {
                                        MessageBox.Show("Rename failed!\r\n\r\n" + exc.Message);
                                        return;
                                    }

                                    if (txFilter.Text == it.strFileName)
                                    {
                                        txFilter.Text = sNewName;
                                    }
                                    it.strFileName = sNewName;

                                    //ReQuery...
                                    lbFiles.ItemsSource = null;
                                    lbFiles.ItemsSource = m_files;
                                }
                            }
                        }
                        else
                        {
                            //NOP...
                        }
                        break;
                    }
                    }
                }

                m_AppArgs.Clear();
            }
        }