Browse Source

QVCopier: Custom Progress Bar; Layout confirm; Controls named

HOME 2 years ago
parent
commit
c8d2baa342

+ 59 - 0
QVCopier/Components/TextProgressBar/README.md

@@ -0,0 +1,59 @@
+# TextProgressBar
+Component based on ProgressBar;
+
+**Have no blinking/flickering**
+
+Have following properties in Visual Studio Properties section:
+
+* Visual mode:
+   - NoText - no text displayed over ProgressBar
+   - Percentage - How many % passed
+   - CurrProgress - "256/500"
+   - CustomText - display Text
+   - TextAndPercentage - "CustomText: 50%"
+   - TextAndCurrProgress - "CustomText: 256/500"
+* TextColour
+* TextFont
+* Text - display custom text in case of selection mode with customText support.
+* ProgressColor
+
+So its really simple in use.
+
+Have wrote no blinking/flickering TextProgressBar
+
+You can find source code here: https://github.com/ukushu/TextProgressBar
+
+
+# Samples
+
+NoText:
+
+[![enter image description here][1]][1]
+
+Percentage mode:
+
+[![no blinking/flickering TextProgressBar][2]][2]
+
+Text Mode:
+
+[![no blinking/flickering TextProgressBar][3]][3]
+
+Progress Mode: 
+
+[![enter image description here][4]][4]
+
+Text + Precentage Mode:
+
+[![enter image description here][5]][5]
+
+Text + Progress mode:
+
+[![enter image description here][6]][6]
+
+
+  [1]: https://i.stack.imgur.com/YKAkC.gif
+  [2]: https://i.stack.imgur.com/mMy7Y.gif
+  [3]: https://i.stack.imgur.com/g1uPL.gif
+  [4]: https://i.stack.imgur.com/FQdNN.gif
+  [5]: https://i.stack.imgur.com/Q3VGZ.gif
+  [6]: https://i.stack.imgur.com/qOMKT.gif

+ 188 - 0
QVCopier/Components/TextProgressBar/TextProgressBarControl.cs

@@ -0,0 +1,188 @@
+using System;
+using System.ComponentModel;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace QVCopier.Components.TextProgressBar
+{
+    public class TextProgressBarControl : ProgressBar
+    {
+        private TextProgressBarDisplayMode _visualMode = TextProgressBarDisplayMode.CurrProgress;
+
+        private readonly StringFormat _stringFormat = new() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
+
+        private string _text = string.Empty;
+        private ContentAlignment _textAlign = ContentAlignment.MiddleCenter;
+
+
+
+        [Category("Additional Options"), Browsable(true)]
+        public TextProgressBarDisplayMode VisualMode
+        {
+            get => _visualMode;
+            set
+            {
+                _visualMode = value;
+                Invalidate();//redraw component after change value from VS Properties section
+            }
+        }
+
+        [DefaultValue(ContentAlignment.MiddleCenter), Browsable(true)]
+        public virtual ContentAlignment TextAlign
+        {
+            get => _textAlign;
+            set
+            {
+                _textAlign = value;
+
+                switch (value)
+                {
+                    case ContentAlignment.TopLeft:
+                        _stringFormat.LineAlignment = StringAlignment.Near;
+                        _stringFormat.Alignment = StringAlignment.Near;
+                        break;
+
+                    case ContentAlignment.TopCenter:
+                        _stringFormat.LineAlignment = StringAlignment.Near;
+                        _stringFormat.Alignment = StringAlignment.Center;
+                        break;
+
+                    case ContentAlignment.TopRight:
+                        _stringFormat.LineAlignment = StringAlignment.Near;
+                        _stringFormat.Alignment = StringAlignment.Far;
+                        break;
+
+                    case ContentAlignment.MiddleLeft:
+                        _stringFormat.LineAlignment = StringAlignment.Center;
+                        _stringFormat.Alignment = StringAlignment.Near;
+                        break;
+
+                    case ContentAlignment.MiddleCenter:
+                        _stringFormat.LineAlignment = StringAlignment.Center;
+                        _stringFormat.Alignment = StringAlignment.Center;
+                        break;
+
+                    case ContentAlignment.MiddleRight:
+                        _stringFormat.LineAlignment = StringAlignment.Center;
+                        _stringFormat.Alignment = StringAlignment.Far;
+                        break;
+
+                    case ContentAlignment.BottomLeft:
+                        _stringFormat.LineAlignment = StringAlignment.Far;
+                        _stringFormat.Alignment = StringAlignment.Near;
+                        break;
+
+                    case ContentAlignment.BottomCenter:
+                        _stringFormat.LineAlignment = StringAlignment.Far;
+                        _stringFormat.Alignment = StringAlignment.Center;
+                        break;
+
+                    case ContentAlignment.BottomRight:
+                        _stringFormat.LineAlignment = StringAlignment.Far;
+                        _stringFormat.Alignment = StringAlignment.Far;
+                        break;
+
+                    default:
+                        throw new ArgumentOutOfRangeException(nameof(value), value, null);
+                }
+
+                Invalidate();//redraw component after change value from VS Properties section
+            }
+        }
+
+        [Description("If it's empty, % will be shown"), Category("Additional Options"), Browsable(true), EditorBrowsable(EditorBrowsableState.Always)]
+        public string CustomText
+        {
+            get => _text;
+            set
+            {
+                _text = value;
+                Invalidate();//redraw component after change value from VS Properties section
+            }
+        }
+
+        private string TextToDraw
+        {
+            get
+            {
+                var text = CustomText;
+
+                switch (VisualMode)
+                {
+                    case TextProgressBarDisplayMode.Percentage:
+                        text = PercentageStr;
+                        break;
+
+                    case TextProgressBarDisplayMode.CurrProgress:
+                        text = CurrProgressStr;
+                        break;
+
+                    case TextProgressBarDisplayMode.TextAndCurrProgress:
+                        text = $"{CustomText}: {CurrProgressStr}";
+                        break;
+
+                    case TextProgressBarDisplayMode.TextAndPercentage:
+                        text = $"{CustomText}: {PercentageStr}";
+                        break;
+                }
+
+                return text;
+            }
+        }
+
+        private string PercentageStr => $"{(int)((float)Value - Minimum) / ((float)Maximum - Minimum) * 100 } %";
+
+        private string CurrProgressStr => $"{Value}/{Maximum}";
+
+        public TextProgressBarControl()
+        {
+            Value = Minimum;
+            FixComponentBlinking();
+        }
+
+        private void FixComponentBlinking()
+        {
+            SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
+        }
+
+        protected override void OnPaint(PaintEventArgs e)
+        {
+            var g = e.Graphics;
+
+            using var brush = new SolidBrush(ForeColor);
+            var rect = ClientRectangle;
+
+            ProgressBarRenderer.DrawHorizontalBar(g, rect);
+
+            rect.Inflate(-3, -3);
+
+            var progressBarRect = new Rectangle(rect.X, rect.Y, (int)Math.Round((float)Value / Maximum * rect.Width), rect.Height);
+
+            if (Value > 0)
+            {
+                g.FillRectangle(brush, progressBarRect);
+            }
+
+            if (VisualMode != TextProgressBarDisplayMode.NoText)
+            {
+                void DrawText(Color c)
+                {
+                    using var br = new SolidBrush(c);
+                    g.DrawString(TextToDraw, Font, br, rect, _stringFormat);
+                }
+
+                g.SetClip(rect);
+                DrawText(ForeColor);
+                g.ResetClip();
+
+                g.SetClip(progressBarRect);
+                DrawText(BackColor);
+                g.ResetClip();
+
+
+            }
+        }
+
+
+    }
+}

+ 12 - 0
QVCopier/Components/TextProgressBar/TextProgressBarDisplayMode.cs

@@ -0,0 +1,12 @@
+namespace QVCopier.Components.TextProgressBar
+{
+    public enum TextProgressBarDisplayMode
+    {
+        NoText,
+        Percentage,
+        CurrProgress,
+        CustomText,
+        TextAndPercentage,
+        TextAndCurrProgress
+    }
+}

+ 2 - 5
QVCopier/Program.cs

@@ -1,18 +1,15 @@
 using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
 using System.Windows.Forms;
 
 namespace QVCopier
 {
-    static class Program
+    internal static class Program
     {
         /// <summary>
         /// 应用程序的主入口点。
         /// </summary>
         [STAThread]
-        static void Main()
+        private static void Main()
         {
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);

+ 20 - 0
QVCopier/QVCopier.csproj

@@ -22,6 +22,7 @@
     <DefineConstants>DEBUG;TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <LangVersion>latest</LangVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <PlatformTarget>AnyCPU</PlatformTarget>
@@ -31,6 +32,7 @@
     <DefineConstants>TRACE</DefineConstants>
     <ErrorReport>prompt</ErrorReport>
     <WarningLevel>4</WarningLevel>
+    <LangVersion>latest</LangVersion>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="System" />
@@ -46,6 +48,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Components\TextProgressBar\TextProgressBarDisplayMode.cs" />
     <Compile Include="QvcMainForm.cs">
       <SubType>Form</SubType>
     </Compile>
@@ -54,6 +57,10 @@
     </Compile>
     <Compile Include="Program.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Components\TextProgressBar\TextProgressBarControl.cs">
+      <SubType>Component</SubType>
+    </Compile>
+    <Compile Include="Utility\ExplorerAccessor.cs" />
     <EmbeddedResource Include="Properties\Resources.resx">
       <Generator>ResXFileCodeGenerator</Generator>
       <LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -66,6 +73,7 @@
     <EmbeddedResource Include="QvcMainForm.resx">
       <DependentUpon>QvcMainForm.cs</DependentUpon>
     </EmbeddedResource>
+    <None Include="Components\TextProgressBar\README.md" />
     <None Include="Properties\Settings.settings">
       <Generator>SettingsSingleFileGenerator</Generator>
       <LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -80,5 +88,17 @@
   <ItemGroup>
     <None Include="App.config" />
   </ItemGroup>
+  <ItemGroup>
+    <COMReference Include="SHDocVw">
+      <Guid>{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}</Guid>
+      <VersionMajor>1</VersionMajor>
+      <VersionMinor>1</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>tlbimp</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+  </ItemGroup>
+  <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>

File diff suppressed because it is too large
+ 625 - 354
QVCopier/QvcMainForm.Designer.cs


+ 0 - 5
QVCopier/QvcMainForm.cs

@@ -16,10 +16,5 @@ namespace QVCopier
         {
             InitializeComponent();
         }
-
-        private void panel1_Paint(object sender, PaintEventArgs e)
-        {
-
-        }
     }
 }

+ 21 - 10
QVCopier/Readme.md

@@ -12,21 +12,32 @@ Alt clone of TeraCopy
   - Pause and resume
   - List operation
     - Tabs to filter by status
-    - Retry
-      -  Error handler when queue finished
-      -  Requeue when not finished yet
-  - Batch delete source files
+    - Manual Retry
+      - Error handler when queue finished
+      - Requeue when not finished yet
+  - Batch delete files in list(context menu)
 - Core
-  - Big buffer for optimize performance and reduce device wear
+  - Keep file attributes and date
   - Verify CheckSum between source and destination
     - Source file read 1 time, calculate checksum and put to buffer
-
-## Future 
-
-- Save / Load progress
+  - Big buffer for optimize performance and reduce device wear
 
 ## Technical details
 
 - Runing Hash calcute
   - HashAlgorithm.HashCore
-  - HashAlgorithm.HashFinal
+  - HashAlgorithm.HashFinal
+- Main procedures
+  - Read source files to buffer and calcuting checksum
+    - Until buffer full
+    - Or read finished
+  - Write dest. files
+    - Goto read if not finished
+  - Do dest. files checksum
+    - Compare with source files
+
+## Future 
+
+- Save / Load progress
+- Mult-threading for diffen drive
+

+ 16 - 0
QVCopier/Utility/ExplorerAccessor.cs

@@ -0,0 +1,16 @@
+using SHDocVw;
+using System;
+using System.IO;
+using System.Linq;
+
+namespace QVCopier.Utility
+{
+    internal static class ExplorerAccessor
+    {
+        public static string[] GetOpenedWindowPath()
+        {
+            var paths = new ShellWindows().Cast<InternetExplorer>().Select(p => Path.GetFullPath(new Uri(p.LocationURL).AbsolutePath)).ToArray();
+            return paths;
+        }
+    }
+}