├── .gitattributes
├── .gitignore
├── COPYING.txt
├── README.md
├── VncViewer.App.Config
├── App.config
├── App.xaml
├── App.xaml.cs
├── Cultures
│ ├── Strings.Designer.cs
│ ├── Strings.pt-BR.Designer.cs
│ ├── Strings.pt-BR.resx
│ └── Strings.resx
├── Icon.ico
├── Icon
│ ├── Icon.afdesign
│ └── Icon.png
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── MainWindowViewModel.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── RelayCommand.cs
└── VncViewer.App.Config.csproj
├── VncViewer.App.Core
├── Config.cs
├── ConfigManager.cs
├── Globals.cs
├── Properties
│ └── AssemblyInfo.cs
├── VncViewer.App.Core.csproj
├── WindowPlacement
│ ├── Point.cs
│ ├── Rect.cs
│ ├── WindowPlacementStruct.cs
│ └── WindowPlacementUtils.cs
└── packages.config
├── VncViewer.App
├── App.config
├── Config.json
├── Cultures
│ ├── Strings.Designer.cs
│ ├── Strings.pt-BR.Designer.cs
│ ├── Strings.pt-BR.resx
│ └── Strings.resx
├── Icon.ico
├── Icon
│ ├── Icon.afdesign
│ └── Icon.png
├── MainWindow.xaml
├── MainWindow.xaml.cs
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
├── VncViewer.App.csproj
├── VncViewerApp.xaml
├── VncViewerApp.xaml.cs
└── packages.config
├── VncViewer.UWP
├── App.xaml
├── App.xaml.cs
├── Assets
│ ├── LockScreenLogo.scale-200.png
│ ├── SplashScreen.scale-200.png
│ ├── Square150x150Logo.scale-200.png
│ ├── Square44x44Logo.scale-200.png
│ ├── Square44x44Logo.targetsize-24_altform-unplated.png
│ ├── StoreLogo.png
│ └── Wide310x150Logo.scale-200.png
├── Config.cs
├── Config.json
├── MainPage.xaml
├── MainPage.xaml.cs
├── Package.appxmanifest
├── Properties
│ ├── AssemblyInfo.cs
│ └── Default.rd.xml
├── VncViewer.UWP.csproj
├── VncViewerControl.xaml
└── VncViewerControl.xaml.cs
├── VncViewer.Vnc
├── Authenticator
│ ├── RfbAuthenticatorBase.cs
│ └── VncAuthenticator.cs
├── Events
│ ├── Delegates.cs
│ ├── DisconnectEventArgs.cs
│ ├── FramebufferUpdateEventArgs.cs
│ └── VncStateChangedEventArgs.cs
├── Exceptions
│ ├── VncException.cs
│ └── VncSecurityException.cs
├── GlobalSuppressions.cs
├── Rfb
│ ├── Decoders
│ │ ├── BaseDecoder.cs
│ │ ├── CopyRectDecoder.cs
│ │ ├── PixelReader.cs
│ │ ├── PixelReader16.cs
│ │ ├── PixelReader32.cs
│ │ ├── PixelReader8.cs
│ │ ├── RawDecoder.cs
│ │ ├── RfbDecoder.cs
│ │ ├── ZlibDecoder.cs
│ │ ├── ZlibDecoderBase.cs
│ │ └── ZrleDecoder.cs
│ ├── Enums
│ │ ├── RfbEncodingType.cs
│ │ └── ServerClientMessageType.cs
│ ├── Framebuffer.cs
│ ├── Messages
│ │ ├── ColorMapEntries.cs
│ │ ├── FramebufferUpdateRequestMessage.cs
│ │ ├── MessageBase.cs
│ │ ├── MessageMemberAttribute.cs
│ │ ├── MessageMemberInfo.cs
│ │ ├── PixelFormat.cs
│ │ ├── ServerInitMessage.cs
│ │ ├── SetEncodingsMessage.cs
│ │ └── SetPixelFormatMessage.cs
│ ├── RfbSerializer.cs
│ ├── RfbVersion.cs
│ ├── RfbVersions.cs
│ └── VncState.cs
├── VncClient.cs
├── VncViewer.Vnc.csproj
└── ZlibStream.cs
├── VncViewer.WPF
├── Cultures
│ ├── Strings.Designer.cs
│ ├── Strings.pt-BR.Designer.cs
│ ├── Strings.pt-BR.resx
│ └── Strings.resx
├── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ └── Resources.resx
├── Resources
│ └── vnccursor.cur
├── VncViewer.WPF.csproj
├── VncViewerControl.xaml
├── VncViewerControl.xaml.cs
├── WritableBitmapWriter.cs
└── packages.config
└── VncViewer.sln
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | bld/
21 | [Bb]in/
22 | [Oo]bj/
23 | [Ll]og/
24 |
25 | # Visual Studio 2015 cache/options directory
26 | .vs/
27 | # Uncomment if you have tasks that create the project's static files in wwwroot
28 | #wwwroot/
29 |
30 | # MSTest test Results
31 | [Tt]est[Rr]esult*/
32 | [Bb]uild[Ll]og.*
33 |
34 | # NUNIT
35 | *.VisualState.xml
36 | TestResult.xml
37 |
38 | # Build Results of an ATL Project
39 | [Dd]ebugPS/
40 | [Rr]eleasePS/
41 | dlldata.c
42 |
43 | # DNX
44 | project.lock.json
45 | project.fragment.lock.json
46 | artifacts/
47 |
48 | *_i.c
49 | *_p.c
50 | *_i.h
51 | *.ilk
52 | *.meta
53 | *.obj
54 | *.pch
55 | *.pdb
56 | *.pgc
57 | *.pgd
58 | *.rsp
59 | *.sbr
60 | *.tlb
61 | *.tli
62 | *.tlh
63 | *.tmp
64 | *.tmp_proj
65 | *.log
66 | *.vspscc
67 | *.vssscc
68 | .builds
69 | *.pidb
70 | *.svclog
71 | *.scc
72 |
73 | # Chutzpah Test files
74 | _Chutzpah*
75 |
76 | # Visual C++ cache files
77 | ipch/
78 | *.aps
79 | *.ncb
80 | *.opendb
81 | *.opensdf
82 | *.sdf
83 | *.cachefile
84 | *.VC.db
85 | *.VC.VC.opendb
86 |
87 | # Visual Studio profiler
88 | *.psess
89 | *.vsp
90 | *.vspx
91 | *.sap
92 |
93 | # TFS 2012 Local Workspace
94 | $tf/
95 |
96 | # Guidance Automation Toolkit
97 | *.gpState
98 |
99 | # ReSharper is a .NET coding add-in
100 | _ReSharper*/
101 | *.[Rr]e[Ss]harper
102 | *.DotSettings.user
103 |
104 | # JustCode is a .NET coding add-in
105 | .JustCode
106 |
107 | # TeamCity is a build add-in
108 | _TeamCity*
109 |
110 | # DotCover is a Code Coverage Tool
111 | *.dotCover
112 |
113 | # NCrunch
114 | _NCrunch_*
115 | .*crunch*.local.xml
116 | nCrunchTemp_*
117 |
118 | # MightyMoose
119 | *.mm.*
120 | AutoTest.Net/
121 |
122 | # Web workbench (sass)
123 | .sass-cache/
124 |
125 | # Installshield output folder
126 | [Ee]xpress/
127 |
128 | # DocProject is a documentation generator add-in
129 | DocProject/buildhelp/
130 | DocProject/Help/*.HxT
131 | DocProject/Help/*.HxC
132 | DocProject/Help/*.hhc
133 | DocProject/Help/*.hhk
134 | DocProject/Help/*.hhp
135 | DocProject/Help/Html2
136 | DocProject/Help/html
137 |
138 | # Click-Once directory
139 | publish/
140 |
141 | # Publish Web Output
142 | *.[Pp]ublish.xml
143 | *.azurePubxml
144 | # TODO: Comment the next line if you want to checkin your web deploy settings
145 | # but database connection strings (with potential passwords) will be unencrypted
146 | #*.pubxml
147 | *.publishproj
148 |
149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
150 | # checkin your Azure Web App publish settings, but sensitive information contained
151 | # in these scripts will be unencrypted
152 | PublishScripts/
153 |
154 | # NuGet Packages
155 | *.nupkg
156 | # The packages folder can be ignored because of Package Restore
157 | **/packages/*
158 | # except build/, which is used as an MSBuild target.
159 | !**/packages/build/
160 | # Uncomment if necessary however generally it will be regenerated when needed
161 | #!**/packages/repositories.config
162 | # NuGet v3's project.json files produces more ignoreable files
163 | *.nuget.props
164 | *.nuget.targets
165 |
166 | # Microsoft Azure Build Output
167 | csx/
168 | *.build.csdef
169 |
170 | # Microsoft Azure Emulator
171 | ecf/
172 | rcf/
173 |
174 | # Windows Store app package directories and files
175 | AppPackages/
176 | BundleArtifacts/
177 | Package.StoreAssociation.xml
178 | _pkginfo.txt
179 |
180 | # Visual Studio cache files
181 | # files ending in .cache can be ignored
182 | *.[Cc]ache
183 | # but keep track of directories ending in .cache
184 | !*.[Cc]ache/
185 |
186 | # Others
187 | ClientBin/
188 | ~$*
189 | *~
190 | *.dbmdl
191 | *.dbproj.schemaview
192 | *.jfm
193 | *.pfx
194 | *.publishsettings
195 | node_modules/
196 | orleans.codegen.cs
197 |
198 | # Since there are multiple workflows, uncomment next line to ignore bower_components
199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
200 | #bower_components/
201 |
202 | # RIA/Silverlight projects
203 | Generated_Code/
204 |
205 | # Backup & report files from converting an old project file
206 | # to a newer Visual Studio version. Backup files are not needed,
207 | # because we have git ;-)
208 | _UpgradeReport_Files/
209 | Backup*/
210 | UpgradeLog*.XML
211 | UpgradeLog*.htm
212 |
213 | # SQL Server files
214 | *.mdf
215 | *.ldf
216 |
217 | # Business Intelligence projects
218 | *.rdl.data
219 | *.bim.layout
220 | *.bim_*.settings
221 |
222 | # Microsoft Fakes
223 | FakesAssemblies/
224 |
225 | # GhostDoc plugin setting file
226 | *.GhostDoc.xml
227 |
228 | # Node.js Tools for Visual Studio
229 | .ntvs_analysis.dat
230 |
231 | # Visual Studio 6 build log
232 | *.plg
233 |
234 | # Visual Studio 6 workspace options file
235 | *.opt
236 |
237 | # Visual Studio LightSwitch build output
238 | **/*.HTMLClient/GeneratedArtifacts
239 | **/*.DesktopClient/GeneratedArtifacts
240 | **/*.DesktopClient/ModelManifest.xml
241 | **/*.Server/GeneratedArtifacts
242 | **/*.Server/ModelManifest.xml
243 | _Pvt_Extensions
244 |
245 | # Paket dependency manager
246 | .paket/paket.exe
247 | paket-files/
248 |
249 | # FAKE - F# Make
250 | .fake/
251 |
252 | # JetBrains Rider
253 | .idea/
254 | *.sln.iml
255 |
256 | # CodeRush
257 | .cr/
258 |
259 | # Python Tools for Visual Studio (PTVS)
260 | __pycache__/
261 | *.pyc
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | VncViewer
2 | --------
3 | VncViewer is my fork of [VncSharp](https://github.com/humphd/VncSharp), its designed to only view the remote framebuffer image.
4 |
5 | It includes a sample WPF and UWP applications.
6 |
7 | #### Supported encodings
8 | 1. Raw
9 | 2. Zlib
10 | 3. Zrle
11 | 4. CopyRect
12 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Net.Sockets;
3 | using System.Security.Cryptography;
4 | using System.Windows;
5 | using VncViewer.App.Config.Cultures;
6 | using VncViewer.App.Core;
7 | using VncViewer.Vnc;
8 |
9 | namespace VncViewer.App.Config
10 | {
11 | ///
12 | /// Interaction logic for App.xaml
13 | ///
14 | public partial class App : Application
15 | {
16 | private Core.Config config;
17 | private MainWindow mainWindow;
18 |
19 | void Application_Startup(object sender, StartupEventArgs e)
20 | {
21 | config = ConfigManager.ReadLocalConfig();
22 | if(config == null)
23 | {
24 | config = new Core.Config();
25 | }
26 |
27 | mainWindow = new MainWindow();
28 | ConfigToViewModel();
29 | mainWindow.Model.SaveAction = SaveConfig;
30 | mainWindow.Model.TestAction = TestConfig;
31 | mainWindow.Show();
32 | }
33 |
34 | private void ConfigToViewModel()
35 | {
36 | var vm = mainWindow.Model;
37 | vm.Port = config.Port;
38 | vm.Host = config.Host;
39 |
40 | try
41 | {
42 | vm.Password = config.GetPassword();
43 | mainWindow.PasswordBox.Password = vm.Password;
44 | }
45 | catch (CryptographicException)
46 | {
47 | MessageBox.Show(Strings.FailedReadPasswordConfigFile, Strings.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
48 | }
49 | }
50 |
51 | private void ViewModelToConfig()
52 | {
53 | var vm = mainWindow.Model;
54 | config.Host = vm.Host;
55 | config.Port = vm.Port;
56 | config.SetPassword(vm.Password);
57 | }
58 |
59 | private void SaveConfig(MainWindowViewModel vm)
60 | {
61 | ViewModelToConfig();
62 | try
63 | {
64 | ConfigManager.SaveToLocalConfig(config);
65 | MessageBox.Show(Strings.ConfigSaved, "Config", MessageBoxButton.OK, MessageBoxImage.Information);
66 | }
67 | catch (Exception e)
68 | {
69 | MessageBox.Show($"{Strings.ConfigSaveFailed}.\r\n{e.Message}", Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
70 | }
71 |
72 | }
73 |
74 | private void TestConfig(MainWindowViewModel vm)
75 | {
76 | using (var client = new VncClient(config.BitsPerPixel, config.Depth))
77 | {
78 | try
79 | {
80 | client.Connect(vm.Host, vm.Port);
81 | client.Authenticate(new VncAuthenticator(vm.Password));
82 | client.Disconnect();
83 | MessageBox.Show("OK.", "Config", MessageBoxButton.OK, MessageBoxImage.Information);
84 | }
85 | catch (SocketException e)
86 | {
87 | MessageBox.Show(e.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
88 | }
89 | catch (VncSecurityException e)
90 | {
91 | MessageBox.Show(e.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
92 | }
93 | catch (Exception e)
94 | {
95 | MessageBox.Show($"{e.Message}\r\n{e.StackTrace}", Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
96 | }
97 |
98 | }
99 |
100 |
101 | }
102 |
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/Cultures/Strings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace VncViewer.App.Config.Cultures {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | public class Strings {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Strings() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | public static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VncViewer.App.Config.Cultures.Strings", typeof(Strings).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | public static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to The config has been saved..
65 | ///
66 | public static string ConfigSaved {
67 | get {
68 | return ResourceManager.GetString("ConfigSaved", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// Looks up a localized string similar to Failed to save..
74 | ///
75 | public static string ConfigSaveFailed {
76 | get {
77 | return ResourceManager.GetString("ConfigSaveFailed", resourceCulture);
78 | }
79 | }
80 |
81 | ///
82 | /// Looks up a localized string similar to Error.
83 | ///
84 | public static string Error {
85 | get {
86 | return ResourceManager.GetString("Error", resourceCulture);
87 | }
88 | }
89 |
90 | ///
91 | /// Looks up a localized string similar to Failed to read password from config file..
92 | ///
93 | public static string FailedReadPasswordConfigFile {
94 | get {
95 | return ResourceManager.GetString("FailedReadPasswordConfigFile", resourceCulture);
96 | }
97 | }
98 |
99 | ///
100 | /// Looks up a localized string similar to Host.
101 | ///
102 | public static string Host {
103 | get {
104 | return ResourceManager.GetString("Host", resourceCulture);
105 | }
106 | }
107 |
108 | ///
109 | /// Looks up a localized string similar to Password.
110 | ///
111 | public static string Password {
112 | get {
113 | return ResourceManager.GetString("Password", resourceCulture);
114 | }
115 | }
116 |
117 | ///
118 | /// Looks up a localized string similar to Port.
119 | ///
120 | public static string Port {
121 | get {
122 | return ResourceManager.GetString("Port", resourceCulture);
123 | }
124 | }
125 |
126 | ///
127 | /// Looks up a localized string similar to Save.
128 | ///
129 | public static string Save {
130 | get {
131 | return ResourceManager.GetString("Save", resourceCulture);
132 | }
133 | }
134 |
135 | ///
136 | /// Looks up a localized string similar to Test.
137 | ///
138 | public static string Test {
139 | get {
140 | return ResourceManager.GetString("Test", resourceCulture);
141 | }
142 | }
143 |
144 | ///
145 | /// Looks up a localized string similar to Warning.
146 | ///
147 | public static string Warning {
148 | get {
149 | return ResourceManager.GetString("Warning", resourceCulture);
150 | }
151 | }
152 | }
153 | }
154 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/Cultures/Strings.pt-BR.Designer.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.App.Config/Cultures/Strings.pt-BR.Designer.cs
--------------------------------------------------------------------------------
/VncViewer.App.Config/Cultures/Strings.pt-BR.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | As configurações foram salvas.
122 |
123 |
124 | Falha ao salvar.
125 |
126 |
127 | Erro
128 |
129 |
130 | Falha ao ler a senha do arquivo de configuração.
131 |
132 |
133 | Host
134 |
135 |
136 | Senha
137 |
138 |
139 | Porta
140 |
141 |
142 | Salvar
143 |
144 |
145 | Testar
146 |
147 |
148 | Aviso
149 |
150 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/Cultures/Strings.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | The config has been saved.
122 |
123 |
124 | Failed to save.
125 |
126 |
127 | Error
128 |
129 |
130 | Failed to read password from config file.
131 |
132 |
133 | Host
134 |
135 |
136 | Password
137 |
138 |
139 | Port
140 |
141 |
142 | Save
143 |
144 |
145 | Test
146 |
147 |
148 | Warning
149 |
150 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/Icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.App.Config/Icon.ico
--------------------------------------------------------------------------------
/VncViewer.App.Config/Icon/Icon.afdesign:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.App.Config/Icon/Icon.afdesign
--------------------------------------------------------------------------------
/VncViewer.App.Config/Icon/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.App.Config/Icon/Icon.png
--------------------------------------------------------------------------------
/VncViewer.App.Config/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
28 |
32 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System.Text.RegularExpressions;
2 | using System.Windows;
3 | using System.Windows.Controls;
4 | using System.Windows.Input;
5 |
6 | namespace VncViewer.App.Config
7 | {
8 | ///
9 | /// Interaction logic for MainWindow.xaml
10 | ///
11 | public partial class MainWindow : Window
12 | {
13 | public MainWindowViewModel Model { get; private set; }
14 |
15 | public MainWindow()
16 | {
17 | Model = new MainWindowViewModel();
18 | this.DataContext = Model;
19 | InitializeComponent();
20 | }
21 |
22 | private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
23 | {
24 | Regex regex = new Regex("[^0-9]+");
25 | e.Handled = regex.IsMatch(e.Text);
26 | }
27 |
28 | private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) => Model.Password = PasswordBox.Password;
29 |
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/MainWindowViewModel.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.ComponentModel;
4 | using System.Diagnostics;
5 | using System.Linq;
6 | using System.Runtime.CompilerServices;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 | using System.Windows;
10 |
11 | namespace VncViewer.App.Config
12 | {
13 | public class MainWindowViewModel : INotifyPropertyChanged
14 | {
15 | private String host;
16 | private int port;
17 | private String password;
18 | private Boolean isEnabled;
19 |
20 | public Action SaveAction { get; set; }
21 | public Action TestAction { get; set; }
22 |
23 | public String Host {
24 | get => host;
25 | set
26 | {
27 | host = value;
28 | OnPropertyRaised();
29 | IsValidChanged();
30 | }
31 | }
32 |
33 | public int Port
34 | {
35 | get => port;
36 | set
37 | {
38 | port = value;
39 | OnPropertyRaised();
40 | IsValidChanged();
41 | }
42 | }
43 |
44 | public String Password
45 | {
46 | get => password;
47 | set
48 | {
49 | password = value;
50 | OnPropertyRaised();
51 | IsValidChanged();
52 | }
53 | }
54 |
55 | public Boolean IsValid
56 | {
57 | get
58 | {
59 | return !String.IsNullOrEmpty(Host) &&
60 | !String.IsNullOrEmpty(Password) &&
61 | Port >= 1 && Port <= 65535;
62 | }
63 | }
64 |
65 | public Boolean IsEnabled
66 | {
67 | get => isEnabled;
68 | set
69 | {
70 | isEnabled = value;
71 | OnPropertyRaised();
72 | }
73 | }
74 |
75 | private void IsValidChanged() => OnPropertyRaised(nameof(IsValid));
76 |
77 | public RelayCommand SaveCommand { get; private set; }
78 | public RelayCommand TestCommand { get; private set; }
79 |
80 | public event PropertyChangedEventHandler PropertyChanged;
81 |
82 | private void OnPropertyRaised([CallerMemberName] string propertyname = null)
83 | {
84 | PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyname));
85 | }
86 |
87 | public MainWindowViewModel()
88 | {
89 | SaveCommand = new RelayCommand(() => this.IsValid, SaveConfig);
90 | TestCommand = new RelayCommand(() => this.IsValid, TestConfig);
91 | IsEnabled = true;
92 | }
93 |
94 | public void SaveConfig()
95 | {
96 | IsEnabled = false;
97 | SaveAction?.Invoke(this);
98 | IsEnabled = true;
99 | }
100 |
101 | public void TestConfig()
102 | {
103 | IsEnabled = false;
104 | TestAction?.Invoke(this);
105 | IsEnabled = true;
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("VncViewer.App.Config")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("VncViewer.App.Config")]
15 | [assembly: AssemblyCopyright("GPL 2")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.1.0.0")]
55 | [assembly: AssemblyFileVersion("1.1.0.0")]
56 | [assembly: Guid("0d3b0574-cb58-484d-b4a3-7368ce522bfc")]
57 | [assembly: NeutralResourcesLanguage("en")]
58 |
59 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace VncViewer.App.Config.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/RelayCommand.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Windows.Input;
3 |
4 | namespace VncViewer.App.Config
5 | {
6 | public class RelayCommand : ICommand
7 | {
8 | private Func canExecute;
9 | private Action execute;
10 |
11 | public RelayCommand(Func canExecute, Action execute)
12 | {
13 | this.canExecute = canExecute;
14 | this.execute = execute;
15 | }
16 |
17 | public event EventHandler CanExecuteChanged
18 | {
19 | add { CommandManager.RequerySuggested += value; }
20 | remove { CommandManager.RequerySuggested -= value; }
21 | }
22 |
23 | public bool CanExecute(object parameter) => canExecute();
24 | public void Execute(object parameter) => execute();
25 |
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/VncViewer.App.Config/VncViewer.App.Config.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {EE0D562A-E907-4F87-93EA-2EBABE1C1578}
8 | WinExe
9 | VncViewer.App.Config
10 | VncViewer.App.Config
11 | v4.7
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 | true
17 |
18 |
19 | AnyCPU
20 | true
21 | full
22 | false
23 | ..\VncViewer.App\bin\Debug\
24 | DEBUG;TRACE
25 | prompt
26 | 4
27 |
28 |
29 | AnyCPU
30 | pdbonly
31 | true
32 | ..\VncViewer.App\bin\Release\
33 | TRACE
34 | prompt
35 | 4
36 |
37 |
38 | Icon.ico
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 | 4.0
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 | MSBuild:Compile
59 | Designer
60 |
61 |
62 |
63 |
64 | Strings.pt-BR.resx
65 | True
66 | True
67 |
68 |
69 | True
70 | True
71 | Strings.resx
72 |
73 |
74 | MSBuild:Compile
75 | Designer
76 |
77 |
78 | App.xaml
79 | Code
80 |
81 |
82 | MainWindow.xaml
83 | Code
84 |
85 |
86 |
87 |
88 | Code
89 |
90 |
91 | True
92 | Settings.settings
93 | True
94 |
95 |
96 | PublicResXFileCodeGenerator
97 | Strings.pt-BR.Designer.cs
98 |
99 |
100 | PublicResXFileCodeGenerator
101 | Strings.Designer.cs
102 |
103 |
104 | SettingsSingleFileGenerator
105 | Settings.Designer.cs
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 | {85fafdcb-f9aa-4e3f-9593-de1d51dd9a40}
114 | VncViewer.App.Core
115 |
116 |
117 | {138298b2-85bc-4579-a386-fb35ecd11843}
118 | VncViewer.Vnc
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/Config.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.IO;
4 | using System.Security.Cryptography;
5 | using System.Text;
6 | using VncViewer.App.Core.WindowPlacement;
7 |
8 | #pragma warning disable CA1819 // Properties should not return arrays
9 |
10 | namespace VncViewer.App.Core
11 | {
12 | public class Config
13 | {
14 | public String Host { get; set; }
15 | public int Port { get; set; } = 5900;
16 | public byte[] ProtectedPassword { get; set; }
17 | public byte BitsPerPixel { get; set; } = 8;
18 | public byte Depth { get; set; } = 8;
19 |
20 | public WindowPlacementStruct? WindowPlacement { get; set; }
21 |
22 | public void SetPassword(String p)
23 | {
24 | if (p != null)
25 | {
26 | ProtectedPassword = ProtectedData.Protect(Encoding.UTF8.GetBytes(p), Globals.Entropy, DataProtectionScope.CurrentUser);
27 | }
28 | }
29 |
30 | public String GetPassword()
31 | {
32 | if (ProtectedPassword == null) return null;
33 |
34 | var p = ProtectedData.Unprotect(ProtectedPassword, Globals.Entropy, DataProtectionScope.CurrentUser);
35 | return Encoding.UTF8.GetString(p);
36 | }
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/ConfigManager.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.IO;
4 | using System.Reflection;
5 |
6 | namespace VncViewer.App.Core
7 | {
8 | public static class ConfigManager
9 | {
10 | public const String LocalConfigFileName = "Config.json";
11 |
12 | public static Config ReadFromFile(String fileName)
13 | {
14 | return JsonConvert.DeserializeObject(File.ReadAllText(fileName));
15 | }
16 |
17 | public static Config ReadLocalConfig()
18 | {
19 | String configFile = GetLocalStringPath();
20 | if (File.Exists(configFile))
21 | {
22 | return ReadFromFile(configFile);
23 | }
24 |
25 | return null;
26 | }
27 |
28 | public static void SaveToLocalConfig(Config config)
29 | {
30 | SaveConfig(config, GetLocalStringPath());
31 | }
32 |
33 | public static String GetLocalStringPath() => Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), LocalConfigFileName);
34 |
35 |
36 | public static void SaveConfig(Config config, String fileName)
37 | {
38 | File.WriteAllText(fileName, JsonConvert.SerializeObject(config, Formatting.Indented));
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/Globals.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.App.Core
2 | {
3 | internal class Globals
4 | {
5 | internal readonly static byte[] Entropy = {0x43,0x6F,0x6E,0x67,0x72,0x61,0x74,0x75,0x6C,0x61,
6 | 0x74,0x69,0x6F,0x6E,0x73,0x2C,0x20,0x79,0x6F,0x75,0x20,0x66,0x6F,0x75,0x6E,0x64,0x20,
7 | 0x61,0x6E,0x20,0x65,0x61,0x73,0x74,0x65,0x72,0x20,0x65,0x67,0x67,0x20,0x3D,0x29};
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Resources;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("VncViewer.App.Core")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("VncViewer.App.Core")]
14 | [assembly: AssemblyCopyright("GPL 2")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 |
18 | // Setting ComVisible to false makes the types in this assembly not visible
19 | // to COM components. If you need to access a type in this assembly from
20 | // COM, set the ComVisible attribute to true on that type.
21 | [assembly: ComVisible(false)]
22 |
23 | // The following GUID is for the ID of the typelib if this project is exposed to COM
24 | [assembly: Guid("85fafdcb-f9aa-4e3f-9593-de1d51dd9a40")]
25 |
26 | // Version information for an assembly consists of the following four values:
27 | //
28 | // Major Version
29 | // Minor Version
30 | // Build Number
31 | // Revision
32 | //
33 | // You can specify all the values or you can default the Build and Revision Numbers
34 | // by using the '*' as shown below:
35 | // [assembly: AssemblyVersion("1.0.*")]
36 | [assembly: AssemblyVersion("1.1.0.0")]
37 | [assembly: AssemblyFileVersion("1.1.0.0")]
38 | [assembly: NeutralResourcesLanguage("en")]
39 |
40 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/VncViewer.App.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {85FAFDCB-F9AA-4E3F-9593-DE1D51DD9A40}
8 | Library
9 | Properties
10 | VncViewer.App.Core
11 | VncViewer.App.Core
12 | v4.7
13 | 512
14 | true
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | ..\packages\Newtonsoft.Json.12.0.2\lib\net45\Newtonsoft.Json.dll
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/WindowPlacement/Point.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace VncViewer.App.Core.WindowPlacement
5 | {
6 | [Serializable]
7 | [StructLayout(LayoutKind.Sequential)]
8 | public struct Point
9 | {
10 | public int X;
11 | public int Y;
12 |
13 | public Point(int x, int y)
14 | {
15 | this.X = x;
16 | this.Y = y;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/WindowPlacement/Rect.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace VncViewer.App.Core.WindowPlacement
5 | {
6 | [Serializable]
7 | [StructLayout(LayoutKind.Sequential)]
8 | public struct Rect
9 | {
10 | public int Left;
11 | public int Top;
12 | public int Right;
13 | public int Bottom;
14 |
15 | public Rect(int left, int top, int right, int bottom)
16 | {
17 | this.Left = left;
18 | this.Top = top;
19 | this.Right = right;
20 | this.Bottom = bottom;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/WindowPlacement/WindowPlacementStruct.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 |
4 | namespace VncViewer.App.Core.WindowPlacement
5 | {
6 | [Serializable]
7 | [StructLayout(LayoutKind.Sequential)]
8 | public struct WindowPlacementStruct
9 | {
10 | public int length;
11 | public int flags;
12 | public int showCmd;
13 | public Point minPosition;
14 | public Point maxPosition;
15 | public Rect normalPosition;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/WindowPlacement/WindowPlacementUtils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Runtime.InteropServices;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 | using System.Windows;
8 | using System.Windows.Interop;
9 |
10 | namespace VncViewer.App.Core.WindowPlacement
11 | {
12 | public static class WindowPlacementUtils
13 | {
14 |
15 | [DllImport("user32.dll")]
16 | private static extern bool SetWindowPlacement(IntPtr hWnd, [In] ref WindowPlacementStruct lpwndpl);
17 |
18 | [DllImport("user32.dll")]
19 | private static extern bool GetWindowPlacement(IntPtr hWnd, out WindowPlacementStruct lpwndpl);
20 |
21 | public const int SW_SHOWNORMAL = 1;
22 | public const int SW_SHOWMINIMIZED = 2;
23 | public const int SW_SHOWMAXIMIZED = 3;
24 |
25 | public static void SetWpfWindowPlacement(Window window, WindowPlacementStruct wpStruct)
26 | {
27 | if (window == null) throw new ArgumentNullException(nameof(window));
28 | SetWindowPlacement(new WindowInteropHelper(window).Handle, ref wpStruct);
29 | }
30 |
31 | public static WindowPlacementStruct GetWpfWindowPlacement(Window window)
32 | {
33 | if (window == null) throw new ArgumentNullException(nameof(window));
34 | WindowPlacementStruct placement = new WindowPlacementStruct();
35 | GetWindowPlacement(new WindowInteropHelper(window).Handle, out placement);
36 | return placement;
37 | }
38 |
39 | }
40 | }
41 |
42 |
43 |
--------------------------------------------------------------------------------
/VncViewer.App.Core/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/VncViewer.App/App.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/VncViewer.App/Config.json:
--------------------------------------------------------------------------------
1 | {
2 | "Host": "localhost",
3 | "Port": 5900,
4 | "Password": "password",
5 | "BitsPerPixel": 8,
6 | "Depth": 8
7 | }
--------------------------------------------------------------------------------
/VncViewer.App/Cultures/Strings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace VncViewer.App.Cultures {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | public class Strings {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Strings() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | public static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VncViewer.App.Cultures.Strings", typeof(Strings).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | public static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to No local config found, please use VncViewer.App.Config..
65 | ///
66 | public static string ConfigNotFound {
67 | get {
68 | return ResourceManager.GetString("ConfigNotFound", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// Looks up a localized string similar to Error.
74 | ///
75 | public static string Error {
76 | get {
77 | return ResourceManager.GetString("Error", resourceCulture);
78 | }
79 | }
80 |
81 | ///
82 | /// Looks up a localized string similar to Failed to get the protect password from config file..
83 | ///
84 | public static string PasswordFromFileReadFailed {
85 | get {
86 | return ResourceManager.GetString("PasswordFromFileReadFailed", resourceCulture);
87 | }
88 | }
89 |
90 | ///
91 | /// Looks up a localized string similar to Trying to connected in {0}s..
92 | ///
93 | public static string TryingConnect {
94 | get {
95 | return ResourceManager.GetString("TryingConnect", resourceCulture);
96 | }
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/VncViewer.App/Cultures/Strings.pt-BR.Designer.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.App/Cultures/Strings.pt-BR.Designer.cs
--------------------------------------------------------------------------------
/VncViewer.App/Cultures/Strings.pt-BR.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | Nenhuma configuração local foi encotnrada, por favor use o VncViewer.App.Config.
122 |
123 |
124 | Erro
125 |
126 |
127 | Falha ao ler a senha do arquivo de configuração.
128 |
129 |
130 | Tentando conectar em {0}s.
131 |
132 |
--------------------------------------------------------------------------------
/VncViewer.App/Cultures/Strings.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | No local config found, please use VncViewer.App.Config.
122 |
123 |
124 | Error
125 |
126 |
127 | Failed to get the protect password from config file.
128 |
129 |
130 | Trying to connected in {0}s.
131 |
132 |
--------------------------------------------------------------------------------
/VncViewer.App/Icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.App/Icon.ico
--------------------------------------------------------------------------------
/VncViewer.App/Icon/Icon.afdesign:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.App/Icon/Icon.afdesign
--------------------------------------------------------------------------------
/VncViewer.App/Icon/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.App/Icon/Icon.png
--------------------------------------------------------------------------------
/VncViewer.App/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/VncViewer.App/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Security.Cryptography;
3 | using System.Threading.Tasks;
4 | using System.Windows;
5 | using VncViewer.App.Core;
6 | using VncViewer.App.Cultures;
7 |
8 | #pragma warning disable CA1305 // Specify IFormatProvider
9 |
10 | namespace VncViewer.App
11 | {
12 | ///
13 | /// Interaction logic for MainWindow.xaml
14 | ///
15 | public partial class MainWindow : Window
16 | {
17 | public Config Config { get; private set; }
18 | public Boolean IsFullScreen { get; private set; }
19 | public WindowState LastWindowState { get; private set; }
20 |
21 | public MainWindow(Config config)
22 | {
23 | Config = config;
24 | IsFullScreen = false;
25 | InitializeComponent();
26 | }
27 |
28 | public void OnConnected()
29 | {
30 | SetTitle($"{vvc.Hostname} - VncViewer");
31 | }
32 |
33 | public async Task HandleConnectionFailed(Exception e)
34 | {
35 | for (int i = 10; i >= 1; i--)
36 | {
37 | vvc.ShowLabelText($"{e.Message}\r\n" + String.Format(Strings.TryingConnect, i));
38 | await Task.Delay(1000).ConfigureAwait(true);
39 | }
40 | }
41 |
42 | public async Task Connect()
43 | {
44 | String vncPassword;
45 | try
46 | {
47 | vncPassword = Config.GetPassword();
48 | }
49 | catch (CryptographicException)
50 | {
51 | MessageBox.Show(Strings.PasswordFromFileReadFailed, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
52 | return;
53 | }
54 |
55 | #pragma warning disable CA1031 // Do not catch general exception types
56 | while (true)
57 | {
58 | try
59 | {
60 | await vvc.ConnectAsync(Config.Host, Config.Port, Config.BitsPerPixel, Config.Depth).ConfigureAwait(true);
61 | await vvc.VncAuthenticate(vncPassword).ConfigureAwait(true);
62 | await vvc.InitializeAsync().ConfigureAwait(true);
63 | OnConnected();
64 | break;
65 | }
66 |
67 | catch (Exception ex)
68 | {
69 | await HandleConnectionFailed(ex).ConfigureAwait(true);
70 | }
71 |
72 | }
73 | #pragma warning restore CA1031 // Do not catch general exception types
74 | }
75 |
76 | private void SetTitle(String title)
77 | {
78 | Dispatcher.Invoke(() => Title = title);
79 | }
80 |
81 | private void VncConnectionLost(object sender, EventArgs e)
82 | {
83 | _ = Dispatcher.InvokeAsync(Connect);
84 | }
85 |
86 | private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
87 | {
88 | vvc.OnDisconnected -= VncConnectionLost;
89 | Config.WindowPlacement = Core.WindowPlacement.WindowPlacementUtils.GetWpfWindowPlacement(this);
90 | }
91 |
92 | private void FullScreen()
93 | {
94 | if (!IsFullScreen)
95 | {
96 | LastWindowState = this.WindowState;
97 | this.WindowState = WindowState.Maximized;
98 |
99 | // hide the window before changing window style
100 | this.Visibility = Visibility.Collapsed;
101 | this.WindowStyle = WindowStyle.None;
102 | this.ResizeMode = ResizeMode.NoResize;
103 |
104 | // re-show the window after changing style
105 | this.Visibility = Visibility.Visible;
106 |
107 | IsFullScreen = !IsFullScreen;
108 | }
109 | else
110 | {
111 | this.WindowState = LastWindowState;
112 | this.WindowStyle = WindowStyle.SingleBorderWindow;
113 | this.ResizeMode = ResizeMode.CanResize;
114 | IsFullScreen = !IsFullScreen;
115 | }
116 | }
117 |
118 | private void Window_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
119 | {
120 | if (e.Key == System.Windows.Input.Key.F11)
121 | {
122 | FullScreen();
123 | }
124 | }
125 |
126 | private async void Window_Loaded(object sender, RoutedEventArgs e)
127 | {
128 | vvc.OnDisconnected += VncConnectionLost;
129 | await Connect().ConfigureAwait(true);
130 | }
131 |
132 | private void Window_SourceInitialized(object sender, EventArgs e)
133 | {
134 | if (Config.WindowPlacement.HasValue)
135 | {
136 | var wp = Config.WindowPlacement.Value;
137 |
138 | if (wp.showCmd == Core.WindowPlacement.WindowPlacementUtils.SW_SHOWMINIMIZED)
139 | wp.showCmd = Core.WindowPlacement.WindowPlacementUtils.SW_SHOWNORMAL;
140 |
141 | Core.WindowPlacement.WindowPlacementUtils.SetWpfWindowPlacement(this, wp);
142 | }
143 | }
144 | }
145 | }
146 |
--------------------------------------------------------------------------------
/VncViewer.App/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("VncViewer.App")]
11 | [assembly: AssemblyDescription("VncViewer WPF Application")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("VncViewer.App")]
15 | [assembly: AssemblyCopyright("GPL 2")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.1.0.0")]
55 | [assembly: AssemblyFileVersion("1.1.0.0")]
56 | [assembly: NeutralResourcesLanguage("en")]
57 | [assembly: Guid("1b4f2ba8-6e12-4140-80dd-9aa0a0eaf7fa")]
58 |
59 |
--------------------------------------------------------------------------------
/VncViewer.App/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace VncViewer.App.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VncViewer.App.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/VncViewer.App/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 | text/microsoft-resx
107 |
108 |
109 | 2.0
110 |
111 |
112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
113 |
114 |
115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
--------------------------------------------------------------------------------
/VncViewer.App/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace VncViewer.App.Properties {
12 |
13 |
14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
17 |
18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
19 |
20 | public static Settings Default {
21 | get {
22 | return defaultInstance;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/VncViewer.App/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/VncViewer.App/VncViewerApp.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/VncViewer.App/VncViewerApp.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Security.Cryptography;
3 | using System.Windows;
4 | using VncViewer.App.Core;
5 | using VncViewer.App.Core.WindowPlacement;
6 | using VncViewer.App.Cultures;
7 |
8 | namespace VncViewer.App
9 | {
10 | public partial class VncViewerApp : Application
11 | {
12 | private MainWindow mainWindow;
13 | private Config config;
14 | public const String AppName = "VncViewer";
15 |
16 | private void Application_Startup(object sender, StartupEventArgs e)
17 | {
18 | config = ConfigManager.ReadLocalConfig();
19 |
20 | if (!CheckConfig())
21 | {
22 | Shutdown();
23 | }
24 | else
25 | {
26 | StartMainWindow();
27 | }
28 | }
29 |
30 | public static MessageBoxResult ShowWarning(String boxText) => MessageBox.Show(boxText, AppName, MessageBoxButton.OK, MessageBoxImage.Warning);
31 | public static MessageBoxResult ShowError(String boxText) => MessageBox.Show(boxText, AppName, MessageBoxButton.OK, MessageBoxImage.Error);
32 |
33 | private Boolean CheckConfig()
34 | {
35 | if(config == null)
36 | {
37 | ShowWarning(Strings.ConfigNotFound);
38 | return false;
39 | }
40 |
41 | try
42 | {
43 | _ = config.GetPassword();
44 | }
45 | catch (CryptographicException)
46 | {
47 | ShowError(Strings.PasswordFromFileReadFailed);
48 | return false;
49 | }
50 |
51 | return true;
52 | }
53 |
54 | private void StartMainWindow()
55 | {
56 | mainWindow = new MainWindow(config);
57 | mainWindow.ShowDialog();
58 | SaveWindowState();
59 | }
60 |
61 | private void SaveWindowState()
62 | {
63 | ConfigManager.SaveToLocalConfig(config);
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/VncViewer.App/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/VncViewer.UWP/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/VncViewer.UWP/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using Windows.ApplicationModel;
7 | using Windows.ApplicationModel.Activation;
8 | using Windows.Foundation;
9 | using Windows.Foundation.Collections;
10 | using Windows.UI.Xaml;
11 | using Windows.UI.Xaml.Controls;
12 | using Windows.UI.Xaml.Controls.Primitives;
13 | using Windows.UI.Xaml.Data;
14 | using Windows.UI.Xaml.Input;
15 | using Windows.UI.Xaml.Media;
16 | using Windows.UI.Xaml.Navigation;
17 |
18 | namespace VncViewer.UWP
19 | {
20 | ///
21 | /// Provides application-specific behavior to supplement the default Application class.
22 | ///
23 | sealed partial class App : Application
24 | {
25 | ///
26 | /// Initializes the singleton application object. This is the first line of authored code
27 | /// executed, and as such is the logical equivalent of main() or WinMain().
28 | ///
29 | public App()
30 | {
31 | this.InitializeComponent();
32 | this.Suspending += OnSuspending;
33 | }
34 |
35 | ///
36 | /// Invoked when the application is launched normally by the end user. Other entry points
37 | /// will be used such as when the application is launched to open a specific file.
38 | ///
39 | /// Details about the launch request and process.
40 | protected override void OnLaunched(LaunchActivatedEventArgs e)
41 | {
42 | Frame rootFrame = Window.Current.Content as Frame;
43 |
44 | // Do not repeat app initialization when the Window already has content,
45 | // just ensure that the window is active
46 | if (rootFrame == null)
47 | {
48 | // Create a Frame to act as the navigation context and navigate to the first page
49 | rootFrame = new Frame();
50 |
51 | rootFrame.NavigationFailed += OnNavigationFailed;
52 |
53 | if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
54 | {
55 | //TODO: Load state from previously suspended application
56 | }
57 |
58 | // Place the frame in the current Window
59 | Window.Current.Content = rootFrame;
60 | }
61 |
62 | if (e.PrelaunchActivated == false)
63 | {
64 | if (rootFrame.Content == null)
65 | {
66 | // When the navigation stack isn't restored navigate to the first page,
67 | // configuring the new page by passing required information as a navigation
68 | // parameter
69 | rootFrame.Navigate(typeof(MainPage), e.Arguments);
70 | }
71 | // Ensure the current window is active
72 | Window.Current.Activate();
73 | }
74 | }
75 |
76 | ///
77 | /// Invoked when Navigation to a certain page fails
78 | ///
79 | /// The Frame which failed navigation
80 | /// Details about the navigation failure
81 | void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
82 | {
83 | throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
84 | }
85 |
86 | ///
87 | /// Invoked when application execution is being suspended. Application state is saved
88 | /// without knowing whether the application will be terminated or resumed with the contents
89 | /// of memory still intact.
90 | ///
91 | /// The source of the suspend request.
92 | /// Details about the suspend request.
93 | private void OnSuspending(object sender, SuspendingEventArgs e)
94 | {
95 | var deferral = e.SuspendingOperation.GetDeferral();
96 | //TODO: Save application state and stop any background activity
97 | deferral.Complete();
98 | }
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/VncViewer.UWP/Assets/LockScreenLogo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.UWP/Assets/LockScreenLogo.scale-200.png
--------------------------------------------------------------------------------
/VncViewer.UWP/Assets/SplashScreen.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.UWP/Assets/SplashScreen.scale-200.png
--------------------------------------------------------------------------------
/VncViewer.UWP/Assets/Square150x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.UWP/Assets/Square150x150Logo.scale-200.png
--------------------------------------------------------------------------------
/VncViewer.UWP/Assets/Square44x44Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.UWP/Assets/Square44x44Logo.scale-200.png
--------------------------------------------------------------------------------
/VncViewer.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.UWP/Assets/Square44x44Logo.targetsize-24_altform-unplated.png
--------------------------------------------------------------------------------
/VncViewer.UWP/Assets/StoreLogo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.UWP/Assets/StoreLogo.png
--------------------------------------------------------------------------------
/VncViewer.UWP/Assets/Wide310x150Logo.scale-200.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.UWP/Assets/Wide310x150Logo.scale-200.png
--------------------------------------------------------------------------------
/VncViewer.UWP/Config.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace VncViewer.UWP
4 | {
5 | public class Config
6 | {
7 | public String Host { get; set; }
8 | public int Port { get; set; }
9 | public String Password { get; set; }
10 | public byte BitsPerPixel { get; set; }
11 | public byte Depth { get; set; }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/VncViewer.UWP/Config.json:
--------------------------------------------------------------------------------
1 | {
2 | "Host": "localhost",
3 | "Port": 5900,
4 | "Password": "password",
5 | "BitsPerPixel": 8,
6 | "Depth": 8
7 | }
--------------------------------------------------------------------------------
/VncViewer.UWP/MainPage.xaml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/VncViewer.UWP/MainPage.xaml.cs:
--------------------------------------------------------------------------------
1 | using Newtonsoft.Json;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Drawing;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Runtime.InteropServices.WindowsRuntime;
8 | using System.Threading.Tasks;
9 | using VncViewerLib;
10 | using Windows.Foundation;
11 | using Windows.Foundation.Collections;
12 | using Windows.Storage;
13 | using Windows.UI.Xaml;
14 | using Windows.UI.Xaml.Controls;
15 | using Windows.UI.Xaml.Controls.Primitives;
16 | using Windows.UI.Xaml.Data;
17 | using Windows.UI.Xaml.Input;
18 | using Windows.UI.Xaml.Media;
19 | using Windows.UI.Xaml.Media.Imaging;
20 | using Windows.UI.Xaml.Navigation;
21 |
22 | // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
23 |
24 | namespace VncViewer.UWP
25 | {
26 |
27 | ///
28 | /// An empty page that can be used on its own or navigated to within a Frame.
29 | ///
30 | public sealed partial class MainPage : Page
31 | {
32 | private VncClient _VncClient;
33 | private WriteableBitmap _VncImage;
34 |
35 | public MainPage()
36 | {
37 | this.InitializeComponent();
38 | }
39 |
40 | private void UpdateRectangle(Stream stream, Framebuffer frambebuffer, Rectangle r )
41 | {
42 | byte[] buffer = new byte[r.Width * 4];
43 |
44 | for (int y = 0; y < r.Height; y++)
45 | {
46 | int p = 4 * (r.X + (r.Y + y) * frambebuffer.Width);
47 | Buffer.BlockCopy(frambebuffer.PixelData, p, buffer, 0, buffer.Length);
48 | stream.Position = p;
49 | stream.Write(buffer, 0, buffer.Length);
50 | }
51 | }
52 |
53 | private async void _VncClient_OnFramebufferUpdate(VncClient sender, FramebufferUpdateEventArgs e)
54 | {
55 | Stream stream = null;
56 |
57 | await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
58 | {
59 | stream = _VncImage.PixelBuffer.AsStream();
60 | });
61 |
62 | foreach (var item in e.Rectangles)
63 | {
64 | UpdateRectangle(stream, e.Framebuffer, item);
65 | }
66 |
67 | await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
68 | {
69 | stream?.Dispose();
70 | _VncImage.Invalidate();
71 | });
72 | }
73 |
74 | private async Task ReadConfigAsync()
75 | {
76 | var packageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation;
77 | var sampleFile = await packageFolder.GetFileAsync("Config.json");
78 | var str = await FileIO.ReadTextAsync(sampleFile);
79 | return JsonConvert.DeserializeObject(str);
80 | }
81 |
82 |
83 | private async void Page_Loaded(object sender, RoutedEventArgs e)
84 | {
85 |
86 | var config = await ReadConfigAsync();
87 |
88 | _VncClient = new VncClient(config.BitsPerPixel, config.Depth);
89 | _VncClient.Connect(config.Host, config.Port);
90 |
91 | var auth = new VncAuthenticator(config.Password);
92 | _VncClient.Authenticate(auth);
93 | _VncClient.Initialize();
94 |
95 | _VncImage = new WriteableBitmap(_VncClient.Framebuffer.Width, _VncClient.Framebuffer.Height);
96 | VncImage.Source = _VncImage;
97 |
98 | _VncClient.OnFramebufferUpdate += _VncClient_OnFramebufferUpdate;
99 | _VncClient.ReceiveUpdates();
100 | }
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/VncViewer.UWP/Package.appxmanifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
9 |
13 |
14 |
15 |
16 |
17 | VncViewer.UWP
18 | ricar
19 | Assets\StoreLogo.png
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
34 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/VncViewer.UWP/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Resources;
2 | using System.Reflection;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 |
6 | // General Information about an assembly is controlled through the following
7 | // set of attributes. Change these attribute values to modify the information
8 | // associated with an assembly.
9 | [assembly: AssemblyTitle("VncViewer.UWP")]
10 | [assembly: AssemblyDescription("")]
11 | [assembly: AssemblyConfiguration("")]
12 | [assembly: AssemblyCompany("")]
13 | [assembly: AssemblyProduct("VncViewer.UWP")]
14 | [assembly: AssemblyCopyright("Copyright © 2018")]
15 | [assembly: AssemblyTrademark("")]
16 | [assembly: AssemblyCulture("")]
17 |
18 | // Version information for an assembly consists of the following four values:
19 | //
20 | // Major Version
21 | // Minor Version
22 | // Build Number
23 | // Revision
24 | //
25 | // You can specify all the values or you can default the Build and Revision Numbers
26 | // by using the '*' as shown below:
27 | // [assembly: AssemblyVersion("1.0.*")]
28 | [assembly: AssemblyVersion("1.0.0.0")]
29 | [assembly: AssemblyFileVersion("1.0.0.0")]
30 | [assembly: ComVisible(false)]
31 | [assembly: AssemblyCopyrightAttribute("GPL 2")]
32 | [assembly: NeutralResourcesLanguageAttribute("en")]
33 |
34 |
--------------------------------------------------------------------------------
/VncViewer.UWP/Properties/Default.rd.xml:
--------------------------------------------------------------------------------
1 |
17 |
18 |
19 |
20 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/VncViewer.UWP/VncViewerControl.xaml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/VncViewer.UWP/VncViewerControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using System.Linq;
5 | using System.Runtime.InteropServices.WindowsRuntime;
6 | using Windows.Foundation;
7 | using Windows.Foundation.Collections;
8 | using Windows.UI.Xaml;
9 | using Windows.UI.Xaml.Controls;
10 | using Windows.UI.Xaml.Controls.Primitives;
11 | using Windows.UI.Xaml.Data;
12 | using Windows.UI.Xaml.Input;
13 | using Windows.UI.Xaml.Media;
14 | using Windows.UI.Xaml.Navigation;
15 |
16 | // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
17 |
18 | namespace VncViewer.UWP
19 | {
20 | public sealed partial class VncViewerControl : UserControl
21 | {
22 | public VncViewerControl()
23 | {
24 | this.InitializeComponent();
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Authenticator/RfbAuthenticatorBase.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.Vnc
2 | {
3 | public abstract class RfbAuthenticator
4 | {
5 | public byte SecurityType { get; private set; }
6 |
7 | protected RfbAuthenticator(byte securityType)
8 | {
9 | SecurityType = securityType;
10 | }
11 |
12 | public abstract void Authenticate(RfbSerializer serializer);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Authenticator/VncAuthenticator.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Security.Cryptography;
3 | using System.Text;
4 |
5 |
6 | #pragma warning disable CA5351 // Do Not Use Broken Cryptographic Algorithms
7 |
8 | namespace VncViewer.Vnc
9 | {
10 | public class VncAuthenticator : RfbAuthenticator
11 | {
12 | private byte[] _PasswordBytes;
13 |
14 | private readonly static byte[] _ReverseByteTable = { 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60,
15 | 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0, 0x8, 0x88, 0x48, 0xC8, 0x28, 0xA8,
16 | 0x68, 0xE8, 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8, 0x4, 0x84, 0x44, 0xC4, 0x24,
17 | 0xA4, 0x64, 0xE4, 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4, 0xC, 0x8C, 0x4C, 0xCC,
18 | 0x2C, 0xAC, 0x6C, 0xEC, 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC, 0x2, 0x82, 0x42,
19 | 0xC2, 0x22, 0xA2, 0x62, 0xE2, 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2, 0xA, 0x8A,
20 | 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA, 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA, 0x6,
21 | 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6, 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
22 | 0xE, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE, 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E,
23 | 0xFE, 0x1, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1, 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1,
24 | 0x71, 0xF1, 0x9, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9, 0x19, 0x99, 0x59, 0xD9, 0x39,
25 | 0xB9, 0x79, 0xF9, 0x5, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5, 0x15, 0x95, 0x55, 0xD5,
26 | 0x35, 0xB5, 0x75, 0xF5, 0xD, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED, 0x1D, 0x9D, 0x5D,
27 | 0xDD, 0x3D, 0xBD, 0x7D, 0xFD, 0x3, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3, 0x13, 0x93,
28 | 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3, 0xB, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB, 0x1B,
29 | 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB, 0x7, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
30 | 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7, 0xF, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F,
31 | 0xEF, 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF };
32 |
33 | public VncAuthenticator(String password) : base(2)
34 | {
35 | if (password == null) throw new ArgumentNullException(nameof(password));
36 | _PasswordBytes = MakeKey(password);
37 | }
38 |
39 | private static byte[] MakeKey(String password)
40 | {
41 | if (password == null) throw new ArgumentNullException(nameof(password));
42 |
43 | var key = Encoding.ASCII.GetBytes(password);
44 | Array.Resize(ref key, 8);
45 |
46 | for (int i = 0; i < 8; i++)
47 | key[i] = _ReverseByteTable[key[i]];
48 |
49 | return key;
50 | }
51 |
52 |
53 | private byte[] EncryptKey(byte[] key, byte[] challenge)
54 | {
55 | if (key == null) throw new ArgumentNullException(nameof(key));
56 | if (challenge == null) throw new ArgumentNullException(nameof(challenge));
57 |
58 |
59 |
60 | using (var des = new DESCryptoServiceProvider()
61 | {
62 | Padding = PaddingMode.None,
63 | Mode = CipherMode.ECB
64 | })
65 |
66 | using (var enc = des.CreateEncryptor(key, null))
67 | {
68 | var response = new byte[16];
69 | enc.TransformBlock(challenge, 0, challenge.Length, response, 0);
70 | return response;
71 | }
72 | }
73 |
74 |
75 | public override void Authenticate(RfbSerializer serializer)
76 | {
77 | if (serializer == null) throw new ArgumentNullException(nameof(serializer));
78 |
79 | var challenge = serializer.ReadBytes(16);
80 | var b = EncryptKey(_PasswordBytes, challenge);
81 | serializer.WriteBytes(b);
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Events/Delegates.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.Vnc
2 | {
3 | public delegate void FrameupdateUpdateEventHandler(VncClient sender, FramebufferUpdateEventArgs e);
4 | public delegate void DisconnectEventHandler(VncClient sender, DisconnectEventArgs e);
5 | public delegate void VncStateChangedEventHandler(VncClient sender, VncStateChangedEventArgs e);
6 | }
7 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Events/DisconnectEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace VncViewer.Vnc
4 | {
5 | public class DisconnectEventArgs : EventArgs
6 | {
7 | public Exception Exception { get; private set; }
8 |
9 | public DisconnectEventArgs(Exception exception)
10 | {
11 | Exception = exception;
12 | }
13 |
14 | public DisconnectEventArgs()
15 | {
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Events/FramebufferUpdateEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 |
5 | namespace VncViewer.Vnc
6 | {
7 | public class FramebufferUpdateEventArgs : EventArgs
8 | {
9 | public Framebuffer Framebuffer { get; private set; }
10 | public IEnumerable Rectangles { get; private set; }
11 |
12 | public FramebufferUpdateEventArgs(Framebuffer framebuffer, IEnumerable rectangles)
13 | {
14 | Framebuffer = framebuffer ?? throw new ArgumentNullException(nameof(framebuffer));
15 | Rectangles = rectangles ?? throw new ArgumentNullException(nameof(rectangles));
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Events/VncStateChangedEventArgs.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace VncViewer.Vnc
4 | {
5 | public class VncStateChangedEventArgs : EventArgs
6 | {
7 | public VncState OldState { get; private set; }
8 | public VncState NewState { get; private set; }
9 |
10 | public VncStateChangedEventArgs(VncState oldState, VncState newState)
11 | {
12 | OldState = oldState;
13 | NewState = newState;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Exceptions/VncException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.Serialization;
3 |
4 | namespace VncViewer.Vnc
5 | {
6 | [Serializable]
7 | public class VncException : Exception
8 | {
9 | public VncException()
10 | {
11 | }
12 |
13 | public VncException(string message) : base(message)
14 | {
15 | }
16 |
17 | public VncException(string message, Exception innerException) : base(message, innerException)
18 | {
19 | }
20 |
21 | protected VncException(SerializationInfo info, StreamingContext context) : base(info, context)
22 | {
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Exceptions/VncSecurityException.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | #pragma warning disable CA1032 // Implement standard exception constructors
4 | #pragma warning disable CA2237
5 |
6 | namespace VncViewer.Vnc
7 | {
8 | public class VncSecurityException : Exception
9 | {
10 | public String Reason { get; protected set; }
11 | public uint SecurityResult { get; protected set; }
12 |
13 | public VncSecurityException(String message, uint securityResult, String reason = null) : base(message)
14 | {
15 | Reason = reason;
16 | SecurityResult = securityResult;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/GlobalSuppressions.cs:
--------------------------------------------------------------------------------
1 |
2 | // This file is used by Code Analysis to maintain SuppressMessage
3 | // attributes that are applied to this project.
4 | // Project-level suppressions either have no target or are given
5 | // a specific target and scoped to a namespace, type, member, etc.
6 |
7 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2208:Instantiate argument exceptions correctly", Justification = "", Scope = "member", Target = "~M:VncViewer.Vnc.RfbVersion.FromString(System.String)~VncViewer.Vnc.RfbVersion")]
8 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA1814:Prefer jagged arrays over multidimensional", Justification = "", Scope = "member", Target = "~M:VncViewer.Vnc.RfbSerializer.ReadColorMapEntries~VncViewer.Vnc.ColorMapEntries")]
9 |
10 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/BaseDecoder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 |
4 | namespace VncViewer.Vnc
5 | {
6 | public abstract class BaseDecoder
7 | {
8 | public Framebuffer Framebuffer { get; private set; }
9 | public RfbSerializer Serializer { get; protected set; }
10 | public PixelReader PixelReader { get; protected set; }
11 |
12 | public BaseDecoder(Framebuffer framebuffer, RfbSerializer rfbSerializer)
13 | {
14 | Framebuffer = framebuffer ?? throw new ArgumentNullException(nameof(framebuffer));
15 | Serializer = rfbSerializer ?? throw new ArgumentNullException(nameof(rfbSerializer));
16 |
17 | var bpp = framebuffer.PixelFormat.BitsPerPixel;
18 |
19 | if (bpp == 32)
20 | {
21 | PixelReader = new PixelReader32(framebuffer, rfbSerializer);
22 | }
23 | else if (bpp == 16)
24 | {
25 | PixelReader = new PixelReader16(framebuffer, rfbSerializer);
26 | }
27 | else if (bpp == 8)
28 | {
29 | PixelReader = new PixelReader8(framebuffer, rfbSerializer);
30 | }
31 | else
32 | {
33 | throw new NotSupportedException();
34 | }
35 | }
36 |
37 | public abstract void Decode(Rectangle r);
38 |
39 | protected void CopyTile(int[] tile, Rectangle destRect)
40 | {
41 | for (int y = 0; y < destRect.Height; y++)
42 | Buffer.BlockCopy(tile, y * destRect.Width * 4, Framebuffer.PixelData, 4 * (destRect.X + (destRect.Y + y) * Framebuffer.Width), destRect.Width * 4);
43 |
44 | }
45 |
46 | protected void FillRect(Rectangle r, int pixel)
47 | {
48 | for (int y = 0; y < r.Height; y++)
49 | {
50 | int z = r.X + (y + r.Y) * Framebuffer.Width;
51 | for (int x = 0; x < r.Width; x++)
52 | {
53 | Framebuffer.PixelData[x + z] = pixel;
54 | }
55 | }
56 | }
57 |
58 |
59 |
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/CopyRectDecoder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Drawing.Imaging;
4 |
5 | namespace VncViewer.Vnc
6 | {
7 | public class CopyRectDecoder : BaseDecoder
8 | {
9 | public CopyRectDecoder(Framebuffer framebuffer, RfbSerializer rfbSerializer) : base(framebuffer, rfbSerializer)
10 | {
11 | }
12 |
13 | public override void Decode(Rectangle r)
14 | {
15 | var p = new Point()
16 | {
17 | X = Serializer.ReadUInt16(),
18 | Y = Serializer.ReadUInt16()
19 | };
20 |
21 | int bufferStride = r.Width * 4;
22 | byte[] buffer = new byte[r.Width * r.Height * 4];
23 |
24 | for (int y = 0; y < r.Height; y++)
25 | {
26 | int s = 4 * (p.X + (p.Y + y) * Framebuffer.Width);
27 | int d = 4 * (y) * r.Width;
28 | Buffer.BlockCopy(Framebuffer.PixelData, s, buffer, d, bufferStride);
29 | }
30 |
31 | for (int y = 0; y < r.Height; y++)
32 | {
33 | int s = 4 * (y) * r.Width;
34 | int d = 4 * (r.X + (r.Y + y) * Framebuffer.Width);
35 | Buffer.BlockCopy(buffer, s, Framebuffer.PixelData, d, bufferStride);
36 | }
37 | }
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/PixelReader.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VncViewer.Vnc
6 | {
7 | public abstract class PixelReader
8 | {
9 | public RfbSerializer Serializer { get; internal set; }
10 | public Framebuffer Framebuffer { get; internal set; }
11 |
12 | private const int _Alpha = 0xFF << 24;
13 |
14 | protected PixelReader(Framebuffer framebuffer, RfbSerializer rfbSerializer)
15 | {
16 | Serializer = rfbSerializer ?? throw new ArgumentNullException(nameof(rfbSerializer));
17 | Framebuffer = framebuffer ?? throw new ArgumentNullException(nameof(framebuffer));
18 | }
19 |
20 | public abstract int ReadPixel();
21 |
22 | protected static int PackPixel(byte red, byte green, byte blue)
23 | {
24 | // Put colour values into proper order for GDI+ (i.e., BGRA, where Alpha is always 0xFF)
25 | return blue & 0xFF | green << 8 | red << 16 | _Alpha;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/PixelReader16.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.Vnc
2 | {
3 | public sealed class PixelReader16 : PixelReader
4 | {
5 | public PixelReader16(Framebuffer framebuffer, RfbSerializer rfbSerializer) : base(framebuffer, rfbSerializer)
6 | {
7 | }
8 |
9 | public override int ReadPixel()
10 | {
11 | var b = Serializer.ReadBytes(2);
12 |
13 | var pixel = (ushort)((uint)b[0] & 0xFF | (uint)b[1] << 8);
14 | var pf = Framebuffer.PixelFormat;
15 |
16 | var red = (byte)(((pixel >> pf.RedShift) & pf.RedMax) * 255 / pf.RedMax);
17 | var green = (byte)(((pixel >> pf.GreenShift) & pf.GreenMax) * 255 / pf.GreenMax);
18 | var blue = (byte)(((pixel >> pf.BlueShift) & pf.BlueMax) * 255 / pf.BlueMax);
19 |
20 | return PackPixel(red, green, blue);
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/PixelReader32.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.Vnc
2 | {
3 | public sealed class PixelReader32 : PixelReader
4 | {
5 | public PixelReader32(Framebuffer framebuffer, RfbSerializer rfbSerializer) : base(framebuffer, rfbSerializer)
6 | {
7 | }
8 |
9 | public override int ReadPixel()
10 | {
11 | // Read the pixel value
12 | var b = Serializer.ReadBytes(4);
13 |
14 | var pixel = (uint)b[0] & 0xFF |
15 | (uint)b[1] << 8 |
16 | (uint)b[2] << 16 |
17 | (uint)b[3] << 24;
18 |
19 | var pf = Framebuffer.PixelFormat;
20 |
21 | // Extract RGB intensities from pixel
22 | var red = (byte)((pixel >> pf.RedShift) & pf.RedMax);
23 | var green = (byte)((pixel >> pf.GreenShift) & pf.GreenMax);
24 | var blue = (byte)((pixel >> pf.BlueShift) & pf.BlueMax);
25 |
26 | return PackPixel(red, green, blue);
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/PixelReader8.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.Vnc
2 | {
3 | public sealed class PixelReader8 : PixelReader
4 | {
5 | public PixelReader8(Framebuffer framebuffer, RfbSerializer rfbSerializer) : base(framebuffer, rfbSerializer)
6 | {
7 | }
8 |
9 | ///
10 | /// Reads an 8-bit pixel.
11 | ///
12 | /// Returns an Integer value representing the pixel in GDI+ format.
13 | public override int ReadPixel()
14 | {
15 | var idx = Serializer.ReadByte();
16 | return PackPixel((byte)Framebuffer.ColorMap[idx, 0], (byte)Framebuffer.ColorMap[idx, 1], (byte)Framebuffer.ColorMap[idx, 2]);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/RawDecoder.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 |
3 | namespace VncViewer.Vnc
4 | {
5 | public class RawDecoder : BaseDecoder
6 | {
7 | public RawDecoder(Framebuffer framebuffer, RfbSerializer rfbSerializer) : base(framebuffer, rfbSerializer)
8 | {
9 | }
10 |
11 | public override void Decode(Rectangle r)
12 | {
13 | for (int y = 0; y < r.Height; y++)
14 | {
15 | int z = r.X + (y + r.Y) * Framebuffer.Width;
16 | for (int x = 0; x < r.Width; x++)
17 | {
18 | Framebuffer.PixelData[x + z] = PixelReader.ReadPixel();
19 | }
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/RfbDecoder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.Threading;
4 |
5 | namespace VncViewer.Vnc
6 | {
7 | public class RfbDecoder : IDisposable
8 | {
9 | public Framebuffer Framebuffer { get; private set; }
10 | public RfbSerializer Serializer { get; private set; }
11 |
12 | public RawDecoder RawDecoder { get; private set; }
13 | public ZlibDecoder ZlibDecoder { get; private set; }
14 | public CopyRectDecoder CopyRectDecoder { get; private set; }
15 | public ZrleDecoder ZrleDecoder { get; private set; }
16 |
17 | private ZlibStream _ZlibStream;
18 |
19 | public readonly static RfbEncodingType[] SupportedDecoders = new RfbEncodingType[] {
20 | RfbEncodingType.CopyRect,
21 | RfbEncodingType.ZRLE,
22 | RfbEncodingType.Zlib,
23 | RfbEncodingType.Raw,
24 | };
25 |
26 | public RfbDecoder(Framebuffer framebuffer, RfbSerializer rfbSerializer)
27 | {
28 | Framebuffer = framebuffer ?? throw new ArgumentNullException(nameof(framebuffer));
29 | Serializer = rfbSerializer ?? throw new ArgumentNullException(nameof(rfbSerializer));
30 |
31 | _ZlibStream = new ZlibStream();
32 | RawDecoder = new RawDecoder(framebuffer, rfbSerializer);
33 | ZlibDecoder = new ZlibDecoder(framebuffer, rfbSerializer, _ZlibStream);
34 | CopyRectDecoder = new CopyRectDecoder(framebuffer, rfbSerializer);
35 | ZrleDecoder = new ZrleDecoder(framebuffer, rfbSerializer, _ZlibStream);
36 | }
37 |
38 | private BaseDecoder GetDecoder(RfbEncodingType enc)
39 | {
40 | switch (enc)
41 | {
42 | case RfbEncodingType.Raw:
43 | return RawDecoder;
44 |
45 | case RfbEncodingType.CopyRect:
46 | return CopyRectDecoder;
47 |
48 | case RfbEncodingType.Zlib:
49 | return ZlibDecoder;
50 |
51 | case RfbEncodingType.ZRLE:
52 | return ZrleDecoder;
53 |
54 | default:
55 | throw new NotImplementedException();
56 | }
57 | }
58 |
59 | public Rectangle[] UpdateFramebuffer(CancellationToken token)
60 | {
61 | Serializer.ReadByte();
62 |
63 | var n = Serializer.ReadUInt16();
64 | var rects = new Rectangle[n];
65 |
66 | for (int i = 0; i < n && !token.IsCancellationRequested; i++)
67 | {
68 | rects[i] = Serializer.ReadRectangle();
69 | var encoding = (RfbEncodingType)Serializer.ReadInt32();
70 | var dec = GetDecoder(encoding);
71 | dec.Decode(rects[i]);
72 | }
73 |
74 | return rects;
75 | }
76 |
77 | #region IDisposable Support
78 | private bool disposedValue = false; // To detect redundant calls
79 |
80 | protected virtual void Dispose(bool disposing)
81 | {
82 | if (!disposedValue)
83 | {
84 | if (disposing)
85 | {
86 | _ZlibStream?.Dispose();
87 | }
88 |
89 | disposedValue = true;
90 | }
91 | }
92 |
93 | public void Dispose()
94 | {
95 | Dispose(true);
96 | GC.SuppressFinalize(this);
97 | }
98 | #endregion
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/ZlibDecoder.cs:
--------------------------------------------------------------------------------
1 | using System.Drawing;
2 |
3 | namespace VncViewer.Vnc
4 | {
5 | public class ZlibDecoder : ZlibDecoderBase
6 | {
7 | private RawDecoder _RawDecoder;
8 |
9 | public ZlibDecoder(Framebuffer framebuffer, RfbSerializer rfbSerializer, ZlibStream zStream) : base(framebuffer, rfbSerializer, zStream)
10 | {
11 | _RawDecoder = new RawDecoder(Framebuffer, new RfbSerializer(zStream));
12 | }
13 |
14 | public override void Decode(Rectangle r)
15 | {
16 | FillBuffer();
17 | _RawDecoder.Decode(r);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/ZlibDecoderBase.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.Vnc
2 | {
3 | public abstract class ZlibDecoderBase : BaseDecoder
4 | {
5 | private ZlibStream _ZlibStream;
6 |
7 | public ZlibDecoderBase(Framebuffer framebuffer, RfbSerializer rfbSerializer, ZlibStream zStream) : base(framebuffer, rfbSerializer)
8 | {
9 | _ZlibStream = zStream;
10 | }
11 |
12 | public virtual void FillBuffer()
13 | {
14 | var len = Serializer.ReadInt32();
15 | var bytes = Serializer.ReadBytes(len);
16 | _ZlibStream.SetBuffer(bytes);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Decoders/ZrleDecoder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 |
4 | namespace VncViewer.Vnc
5 | {
6 | public class ZrleDecoder : ZlibDecoderBase
7 | {
8 | private RfbSerializer _DSerializer;
9 | private RawDecoder _RawDecoder;
10 |
11 | private const ushort TileWidth = 64;
12 | private const ushort TileHeight = 64;
13 |
14 | private int[] _Palette = new int[128];
15 | private int[] _TileBuffer = new int[TileWidth * TileHeight];
16 |
17 | public ZrleDecoder(Framebuffer framebuffer, RfbSerializer rfbSerializer, ZlibStream zStream) : base(framebuffer, rfbSerializer, zStream)
18 | {
19 | if (framebuffer == null) throw new ArgumentNullException(nameof(framebuffer));
20 |
21 | _DSerializer = new RfbSerializer(zStream);
22 |
23 | var bpp = framebuffer.PixelFormat.BitsPerPixel;
24 |
25 | if (bpp == 32)
26 | {
27 | throw new NotImplementedException();
28 | }
29 | else if (bpp == 16)
30 | {
31 | PixelReader = new PixelReader16(framebuffer, _DSerializer);
32 | }
33 | else if (bpp == 8)
34 | {
35 | PixelReader = new PixelReader8(framebuffer, _DSerializer);
36 | }
37 |
38 | _RawDecoder = new RawDecoder(Framebuffer, _DSerializer);
39 | }
40 |
41 | private void ReadZrlePackedPixels(int tw, int th, int[] palette, int palSize, int[] tile)
42 | {
43 | var bppp = palSize > 16 ? 8 :
44 | (palSize > 4 ? 4 : (palSize > 2 ? 2 : 1));
45 | var ptr = 0;
46 |
47 | for (var i = 0; i < th; i++)
48 | {
49 | var eol = ptr + tw;
50 | var b = 0;
51 | var nbits = 0;
52 |
53 | while (ptr < eol)
54 | {
55 | if (nbits == 0)
56 | {
57 | b = _DSerializer.ReadByte();
58 | nbits = 8;
59 | }
60 | nbits -= bppp;
61 | var index = (b >> nbits) & ((1 << bppp) - 1) & 127;
62 | tile[ptr++] = palette[index];
63 | }
64 | }
65 | }
66 |
67 | private void ReadZrlePlainRLEPixels(int tw, int th, int[] tileBuffer)
68 | {
69 | var ptr = 0;
70 | var end = ptr + tw * th;
71 | while (ptr < end)
72 | {
73 | var pix = PixelReader.ReadPixel();
74 | var len = 1;
75 | int b;
76 | do
77 | {
78 | b = _DSerializer.ReadByte();
79 | len += b;
80 | } while (b == byte.MaxValue);
81 |
82 | while (len-- > 0) tileBuffer[ptr++] = pix;
83 | }
84 | }
85 |
86 | private void ReadZrlePackedRLEPixels(int tw, int th, int[] palette, int[] tile)
87 | {
88 | var ptr = 0;
89 | var end = ptr + tw * th;
90 | while (ptr < end)
91 | {
92 | int index = _DSerializer.ReadByte();
93 | var len = 1;
94 | if ((index & 128) != 0)
95 | {
96 | int b;
97 | do
98 | {
99 | b = _DSerializer.ReadByte();
100 | len += b;
101 | } while (b == byte.MaxValue);
102 | }
103 |
104 | index &= 127;
105 |
106 | while (len-- > 0) tile[ptr++] = palette[index];
107 | }
108 | }
109 |
110 | public override void Decode(Rectangle r)
111 | {
112 | FillBuffer();
113 |
114 | for (var ty = 0; ty < r.Height; ty += TileHeight)
115 | {
116 | var th = Math.Min(r.Height - ty, TileHeight);
117 |
118 | for (var tx = 0; tx < r.Width; tx += TileWidth)
119 | {
120 | var tw = Math.Min(r.Width - tx, TileWidth);
121 |
122 | var subencoding = _DSerializer.ReadByte();
123 |
124 | if (subencoding >= 17 && subencoding <= 127 || subencoding == 129)
125 | throw new VncException("Invalid subencoding value");
126 |
127 | var isRLE = (subencoding & 128) != 0;
128 | var paletteSize = subencoding & 127;
129 |
130 | var tileRect = new Rectangle(tx, ty, tw, th);
131 | var destRect = new Rectangle(tx + r.X, ty + r.Y, tw, th);
132 |
133 | // Fill palette
134 | for (var i = 0; i < paletteSize; i++)
135 | _Palette[i] = PixelReader.ReadPixel();
136 |
137 | if (paletteSize == 1)
138 | {
139 | FillRect(destRect, _Palette[0]);
140 | continue;
141 | }
142 |
143 | if (!isRLE)
144 | {
145 | if (paletteSize == 0)
146 | _RawDecoder.Decode(destRect); // Raw Pixel
147 | else
148 | ReadZrlePackedPixels(tw, th, _Palette, paletteSize, _TileBuffer); // Packed palette
149 |
150 | }
151 | else
152 | {
153 | if (paletteSize == 0)
154 | ReadZrlePlainRLEPixels(tw, th, _TileBuffer); // Plain RLE
155 | else
156 | ReadZrlePackedRLEPixels(tw, th, _Palette, _TileBuffer); // Packed RLE palette
157 |
158 | }
159 |
160 | CopyTile(_TileBuffer, destRect);
161 | }
162 | }
163 | }
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Enums/RfbEncodingType.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.Vnc
2 | {
3 | public enum RfbEncodingType : int
4 | {
5 | Raw = 0,
6 | CopyRect = 1,
7 | RRE = 2,
8 | CoRRE = 4,
9 | Hextile = 5,
10 | Zlib = 6,
11 | Tight = 7,
12 | ZlibHex = 8,
13 | Ultra = 9,
14 | Ultra2 = 10,
15 | TRLE = 15,
16 | ZRLE = 16,
17 | ZYWRLE = 17,
18 | H264 = 20,
19 | Jpeg = 21,
20 | Jrle = 22,
21 | TightPng = -260,
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Enums/ServerClientMessageType.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | #pragma warning disable CA1028 // Enum Storage should be Int32
6 |
7 | namespace VncViewer.Vnc
8 | {
9 | public enum ServerClientMessageType : byte
10 | {
11 | // Must support
12 | FramebufferUpdate = 0,
13 | SetColourMapEntries = 1,
14 | Bell = 2,
15 | ServerCutText = 3,
16 |
17 | // Optional
18 | ResizeFrameBuffer = 4,
19 | KeyFrameUpdate = 5,
20 | FileTransfer = 7,
21 | TextChat = 11,
22 | KeepAlive = 13
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Framebuffer.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | #pragma warning disable CA1819 // Properties should not return arrays
4 | #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
5 |
6 | namespace VncViewer.Vnc
7 | {
8 | public class Framebuffer
9 | {
10 | public String Name { get; set; }
11 | public int[] PixelData { get; private set; }
12 |
13 | public ushort Width { get; private set; }
14 | public ushort Height { get; private set; }
15 | public PixelFormat PixelFormat { get; private set; }
16 |
17 | public ushort[,] ColorMap { get; private set; } = new ushort[256, 3];
18 |
19 | public Framebuffer(ushort width, ushort height, PixelFormat pixelFormat)
20 | {
21 | Width = width;
22 | Height = height;
23 |
24 | PixelFormat = pixelFormat ?? throw new ArgumentNullException(nameof(pixelFormat));
25 | PixelData = new int[width * height];
26 | }
27 |
28 | public void UpdateColorMap(ColorMapEntries map)
29 | {
30 | if (map == null) throw new ArgumentNullException(nameof(map));
31 |
32 | for (int i = 0; i < map.Map.GetLength(0); i++)
33 | {
34 | ColorMap[map.FirstColour + i, 0] = map.Map[i, 0];
35 | ColorMap[map.FirstColour + i, 1] = map.Map[i, 1];
36 | ColorMap[map.FirstColour + i, 2] = map.Map[i, 2];
37 | }
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Messages/ColorMapEntries.cs:
--------------------------------------------------------------------------------
1 | #pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
2 | #pragma warning disable CA1819 // Properties should not return arrays
3 |
4 | namespace VncViewer.Vnc
5 | {
6 | public class ColorMapEntries
7 | {
8 | public ushort FirstColour { get; set; }
9 | public ushort[,] Map { get; set; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Messages/FramebufferUpdateRequestMessage.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.Vnc
2 | {
3 | public class FramebufferUpdateRequestMessage : MessageBase
4 | {
5 | [MessageMember(1)]
6 | public bool Incremental { get; set; }
7 |
8 | [MessageMember(2)]
9 | public ushort X { get; set; }
10 |
11 | [MessageMember(3)]
12 | public ushort Y { get; set; }
13 |
14 | [MessageMember(4)]
15 | public ushort Width { get; set; }
16 |
17 | [MessageMember(5)]
18 | public ushort Height { get; set; }
19 |
20 | public FramebufferUpdateRequestMessage() : base(3)
21 | {
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Messages/MessageBase.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VncViewer.Vnc
6 | {
7 | public abstract class MessageBase
8 | {
9 | [MessageMember(0)]
10 | public byte MessageType { get; private set; }
11 |
12 | public MessageBase(byte messageType)
13 | {
14 | MessageType = messageType;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Messages/MessageMemberAttribute.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | namespace VncViewer.Vnc
6 | {
7 | [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
8 | public class MessageMemberAttribute : Attribute
9 | {
10 | public int Index { get; private set; }
11 | public int Size { get; private set; }
12 |
13 | public MessageMemberAttribute(int index, int size = 0)
14 | {
15 | Index = index;
16 | Size = size;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Messages/MessageMemberInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Reflection;
3 |
4 | #pragma warning disable CA1720 // Identifier contains type name
5 |
6 | namespace VncViewer.Vnc
7 | {
8 | public class MessageMemberInfo
9 | {
10 | public Object Value { get; private set; }
11 | public PropertyInfo PropertyInfo { get; private set; }
12 | public MessageMemberAttribute MessageMemberAttribute { get; private set; }
13 | public Type Type { get; private set; }
14 |
15 |
16 | public static MessageMemberInfo FromPropertyInfo(PropertyInfo pi, Object obj)
17 | {
18 | if (pi == null) throw new ArgumentNullException(nameof(pi));
19 |
20 | return new MessageMemberInfo()
21 | {
22 | MessageMemberAttribute = pi.GetCustomAttribute(),
23 | Value = pi.GetValue(obj),
24 | PropertyInfo = pi,
25 | Type = pi.PropertyType
26 | };
27 |
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Messages/PixelFormat.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | #pragma warning disable CA1819 // Properties should not return arrays
4 |
5 | namespace VncViewer.Vnc
6 | {
7 | public class PixelFormat
8 | {
9 | [MessageMember(0)]
10 | public byte BitsPerPixel { get; set; }
11 |
12 | [MessageMember(1)]
13 | public byte Depth { get; set; }
14 |
15 | [MessageMember(2)]
16 | public bool IsBigEndian { get; set; }
17 |
18 | [MessageMember(3)]
19 | public bool IsTrueColour { get; set; }
20 |
21 | [MessageMember(4)]
22 | public ushort RedMax { get; set; }
23 |
24 | [MessageMember(5)]
25 | public ushort GreenMax { get; set; }
26 |
27 | [MessageMember(6)]
28 | public ushort BlueMax { get; set; }
29 |
30 | [MessageMember(7)]
31 | public byte RedShift { get; set; }
32 |
33 | [MessageMember(8)]
34 | public byte GreenShift { get; set; }
35 |
36 | [MessageMember(9)]
37 | public byte BlueShift { get; set; }
38 |
39 | [MessageMember(10, 3)]
40 | public byte[] Padding { get; private set; }
41 |
42 | public PixelFormat()
43 | {
44 | Padding = new byte[3];
45 | }
46 |
47 | public PixelFormat(byte bitsPerPixel, byte depth) : this()
48 | {
49 | BitsPerPixel = bitsPerPixel;
50 | Depth = depth;
51 |
52 | if ((bitsPerPixel == 16) && (depth == 16))
53 | {
54 | IsTrueColour = false;
55 | RedMax = 31;
56 | GreenMax = 63;
57 | BlueMax = 31;
58 | RedShift = 11;
59 | GreenShift = 5;
60 | BlueShift = 0;
61 | }
62 | else if ((bitsPerPixel) == 16 && (depth == 8))
63 | {
64 | IsTrueColour = false;
65 | RedMax = 31;
66 | GreenMax = 63;
67 | BlueMax = 31;
68 | RedShift = 11;
69 | GreenShift = 5;
70 | BlueShift = 0;
71 | }
72 | else if ((bitsPerPixel) == 8 && (depth == 8))
73 | {
74 | IsTrueColour = false;
75 | RedMax = 7;
76 | GreenMax = 7;
77 | BlueMax = 3;
78 | RedShift = 0;
79 | GreenShift = 3;
80 | BlueShift = 6;
81 | }
82 | else if ((bitsPerPixel) == 8 && (depth == 6))
83 | {
84 | IsTrueColour = false;
85 | RedMax = 3;
86 | GreenMax = 3;
87 | BlueMax = 3;
88 | RedShift = 4;
89 | GreenShift = 2;
90 | BlueShift = 0;
91 | }
92 | else if ((bitsPerPixel == 8) && (depth == 3))
93 | {
94 | IsTrueColour = false;
95 | RedMax = 1;
96 | GreenMax = 1;
97 | BlueMax = 1;
98 | RedShift = 2;
99 | GreenShift = 1;
100 | BlueShift = 0;
101 | }
102 | else throw new NotImplementedException();
103 | }
104 | }
105 | }
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Messages/ServerInitMessage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace VncViewer.Vnc
4 | {
5 | public class ServerInitMessage
6 | {
7 | public ushort FramebufferWidth { get; set; }
8 | public ushort FramebufferHeight { get; set; }
9 | public PixelFormat PixelFormat { get; set; }
10 | public String Name { get; set; }
11 |
12 | public override string ToString()
13 | {
14 | return $"{FramebufferWidth}x{FramebufferHeight} {Name}";
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Messages/SetEncodingsMessage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 |
6 | #pragma warning disable CA1819 // Properties should not return arrays
7 |
8 | namespace VncViewer.Vnc
9 | {
10 | public class SetEncodingsMessage : MessageBase
11 | {
12 | [MessageMember(1)]
13 | public byte Padding { get; private set; }
14 |
15 | [MessageMember(2)]
16 | public short NumberOfEncodings { get; private set; }
17 |
18 | [MessageMember(3)]
19 |
20 | public int[] Encodings { get; private set; }
21 |
22 | public SetEncodingsMessage(RfbEncodingType[] encodings) : base(2)
23 | {
24 | if (encodings == null) throw new ArgumentNullException(nameof(encodings));
25 | if (encodings.Length > short.MaxValue) throw new ArgumentOutOfRangeException(nameof(encodings), "Too many encodings.");
26 |
27 | NumberOfEncodings = (short)encodings.Length;
28 | Encodings = encodings.Select(e => (int)e).ToArray();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/Messages/SetPixelFormatMessage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | #pragma warning disable CA1819 // Properties should not return arrays
6 |
7 | namespace VncViewer.Vnc
8 | {
9 | public class SetPixelFormatMessage : MessageBase
10 | {
11 | [MessageMember(1, 3)]
12 |
13 | public byte[] Padding { get; private set; }
14 |
15 | [MessageMember(2)]
16 | public PixelFormat PixelFormat { get; set; }
17 |
18 | public SetPixelFormatMessage(PixelFormat pixelFormat) : base(0)
19 | {
20 | Padding = new byte[3];
21 | PixelFormat = pixelFormat;
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/RfbVersion.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Globalization;
3 | using System.Text.RegularExpressions;
4 |
5 | namespace VncViewer.Vnc
6 | {
7 | public struct RfbVersion : IEquatable, IComparable
8 | {
9 | public int Major { get; private set; }
10 | public int Minor { get; private set; }
11 |
12 | private static readonly Regex _Regex = new Regex(@"RFB (\d{3})\.(\d{3})\n");
13 |
14 | public RfbVersion(int major, int minor)
15 | {
16 | if (major < 0 || major > 999) throw new ArgumentOutOfRangeException(nameof(major));
17 | if (minor < 0 || minor > 999) throw new ArgumentOutOfRangeException(nameof(minor));
18 |
19 | Major = major;
20 | Minor = minor;
21 | }
22 |
23 | public static RfbVersion FromString(String str)
24 | {
25 | if (String.IsNullOrEmpty(str)) throw new ArgumentException(nameof(str));
26 |
27 | var m = _Regex.Match(str);
28 |
29 | if (m.Success)
30 | {
31 | var major = m.Groups[1].ToString();
32 | var minor = m.Groups[2].ToString();
33 | return new RfbVersion(int.Parse(major, CultureInfo.InvariantCulture), int.Parse(minor, CultureInfo.InvariantCulture));
34 | }
35 |
36 | throw new ArgumentException(nameof(str));
37 | }
38 |
39 | public override string ToString() => String.Format(CultureInfo.InvariantCulture, "RFB {0:000}.{1:000}\n", Major, Minor);
40 |
41 | public override bool Equals(object obj)
42 | {
43 | if (!(obj is RfbVersion))
44 | {
45 | return false;
46 | }
47 |
48 | var version = (RfbVersion)obj;
49 | return Major == version.Major &&
50 | Minor == version.Minor;
51 | }
52 |
53 | public override int GetHashCode()
54 | {
55 | var hashCode = 317314336;
56 | hashCode = hashCode * -1521134295 + Major.GetHashCode();
57 | hashCode = hashCode * -1521134295 + Minor.GetHashCode();
58 | return hashCode;
59 | }
60 |
61 | public bool Equals(RfbVersion other) => this.Major == other.Major && this.Minor == other.Minor;
62 |
63 | public static bool operator ==(RfbVersion c1, RfbVersion c2) => c1.Major == c2.Major && c1.Minor == c2.Minor;
64 | public static bool operator !=(RfbVersion c1, RfbVersion c2) => !(c1.Major == c2.Major && c1.Minor == c2.Minor);
65 |
66 | public static bool operator <(RfbVersion c1, RfbVersion c2) => c1.Major <= c2.Major && c1.Minor < c2.Minor;
67 | public static bool operator >(RfbVersion c1, RfbVersion c2) => c2.Major <= c1.Major && c2.Minor < c1.Minor;
68 |
69 | public static bool operator <=(RfbVersion c1, RfbVersion c2) => c1.Major <= c2.Major && c1.Minor <= c2.Minor;
70 | public static bool operator >=(RfbVersion c1, RfbVersion c2) => c2.Major <= c1.Major && c2.Minor <= c1.Minor;
71 |
72 | public int CompareTo(RfbVersion other)
73 | {
74 | var c1 = this.Major.CompareTo(other.Major);
75 | if (c1 != 0) return c1;
76 | return this.Minor.CompareTo(other.Minor);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/RfbVersions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Text;
4 |
5 | #pragma warning disable CA1707 // Identifiers should not contain underscores
6 |
7 | namespace VncViewer.Vnc
8 | {
9 | public static class RfbVersions
10 | {
11 | public static readonly RfbVersion v3_3 = new RfbVersion(3, 3);
12 | public static readonly RfbVersion v3_7 = new RfbVersion(3, 7);
13 | public static readonly RfbVersion v3_8 = new RfbVersion(3, 8);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/Rfb/VncState.cs:
--------------------------------------------------------------------------------
1 | namespace VncViewer.Vnc
2 | {
3 | public enum VncState
4 | {
5 | NotConnected,
6 | Connecting,
7 | Connected,
8 | Authenticating,
9 | Authenticated,
10 | Initializing,
11 | Initialized,
12 | ReceivingMessages,
13 | Disconnecting,
14 | Disconnected
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/VncViewer.Vnc.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0;net47
5 | .NET Standard VNC Client Library
6 |
7 | GPL 2
8 | Ricardo Brito, David Humphrey
9 | https://www.gnu.org/licenses/gpl-2.0.html
10 | VncViewer.Vnc
11 | VncViewer.Vnc
12 |
13 |
14 |
15 | true
16 |
17 |
18 |
19 | true
20 |
21 |
22 |
23 |
24 | all
25 | runtime; build; native; contentfiles; analyzers
26 |
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/VncViewer.Vnc/ZlibStream.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 | using System.IO.Compression;
4 | using System.Threading;
5 | using System.Threading.Tasks;
6 |
7 | namespace VncViewer.Vnc
8 | {
9 | public class ZlibStream : Stream
10 | {
11 | private MemoryStream _Buffer;
12 | private DeflateStream _DeflateStream;
13 | private Boolean _SkippedHeader;
14 |
15 | public ZlibStream()
16 | {
17 | _Buffer = new MemoryStream();
18 | _DeflateStream = new DeflateStream(_Buffer, CompressionMode.Decompress);
19 | _SkippedHeader = false;
20 | }
21 |
22 | public override bool CanRead => true;
23 | public override bool CanSeek => false;
24 | public override bool CanWrite => false;
25 |
26 | public override long Length => throw new NotSupportedException();
27 | public override long Position { get => throw new NotSupportedException(); set => throw new NotSupportedException(); }
28 | public override void Flush() => throw new NotSupportedException();
29 |
30 | public void SetBuffer(byte[] b)
31 | {
32 | if (b == null) throw new ArgumentNullException(nameof(b));
33 |
34 | _Buffer.SetLength(b.Length);
35 | _Buffer.Position = 0;
36 | _Buffer.Write(b, 0, b.Length);
37 |
38 | // Skip the zlib header.
39 | if (!_SkippedHeader)
40 | {
41 | _Buffer.Position = 2;
42 | _SkippedHeader = true;
43 | }
44 | else
45 | {
46 | _Buffer.Position = 0;
47 | }
48 | }
49 |
50 | public override int Read(byte[] buffer, int offset, int count) => _DeflateStream.Read(buffer, offset, count);
51 | public override int ReadByte() => _DeflateStream.ReadByte();
52 | public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) => _DeflateStream.BeginRead(buffer, offset, count, callback, state);
53 | public override Task ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken) => _DeflateStream.ReadAsync(buffer, offset, count, cancellationToken);
54 | public override int EndRead(IAsyncResult asyncResult) => _DeflateStream.EndRead(asyncResult);
55 |
56 | public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException();
57 | public override void SetLength(long value) => throw new NotSupportedException();
58 | public override void Write(byte[] buffer, int offset, int count) => throw new NotSupportedException();
59 |
60 | protected override void Dispose(bool disposing)
61 | {
62 | _Buffer?.Dispose();
63 | _DeflateStream?.Dispose();
64 | base.Dispose(disposing);
65 | }
66 |
67 |
68 |
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/VncViewer.WPF/Cultures/Strings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace VncViewer.WPF.Cultures {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | public class Strings {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Strings() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | public static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VncViewer.WPF.Cultures.Strings", typeof(Strings).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | public static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized string similar to Authenticating.
65 | ///
66 | public static string Authenticating {
67 | get {
68 | return ResourceManager.GetString("Authenticating", resourceCulture);
69 | }
70 | }
71 |
72 | ///
73 | /// Looks up a localized string similar to Authentication failed.
74 | ///
75 | public static string AuthenticationFailed {
76 | get {
77 | return ResourceManager.GetString("AuthenticationFailed", resourceCulture);
78 | }
79 | }
80 |
81 | ///
82 | /// Looks up a localized string similar to Connecting to VNC host {0} please wait....
83 | ///
84 | public static string ConnectingToHost {
85 | get {
86 | return ResourceManager.GetString("ConnectingToHost", resourceCulture);
87 | }
88 | }
89 |
90 | ///
91 | /// Looks up a localized string similar to Disconnected.
92 | ///
93 | public static string Disconnected {
94 | get {
95 | return ResourceManager.GetString("Disconnected", resourceCulture);
96 | }
97 | }
98 |
99 | ///
100 | /// Looks up a localized string similar to Failed to connect.
101 | ///
102 | public static string FailedConnect {
103 | get {
104 | return ResourceManager.GetString("FailedConnect", resourceCulture);
105 | }
106 | }
107 |
108 | ///
109 | /// Looks up a localized string similar to Host is invalid..
110 | ///
111 | public static string HostInvalid {
112 | get {
113 | return ResourceManager.GetString("HostInvalid", resourceCulture);
114 | }
115 | }
116 |
117 | ///
118 | /// Looks up a localized string similar to Initializing.
119 | ///
120 | public static string Initializing {
121 | get {
122 | return ResourceManager.GetString("Initializing", resourceCulture);
123 | }
124 | }
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/VncViewer.WPF/Cultures/Strings.pt-BR.Designer.cs:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.WPF/Cultures/Strings.pt-BR.Designer.cs
--------------------------------------------------------------------------------
/VncViewer.WPF/Cultures/Strings.pt-BR.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | Autenticando
122 |
123 |
124 | Autenticação falhou
125 |
126 |
127 | Conectando no VNC host {0}, por favor aguarde...
128 |
129 |
130 | Desconectado
131 |
132 |
133 | Conexão falhou
134 |
135 |
136 | Host é inválido.
137 |
138 |
139 | Iniciando
140 |
141 |
--------------------------------------------------------------------------------
/VncViewer.WPF/Cultures/Strings.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 | Authenticating
122 |
123 |
124 | Authentication failed
125 |
126 |
127 | Connecting to VNC host {0} please wait...
128 |
129 |
130 | Disconnected
131 |
132 |
133 | Failed to connect
134 |
135 |
136 | Host is invalid.
137 |
138 |
139 | Initializing
140 |
141 |
--------------------------------------------------------------------------------
/VncViewer.WPF/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // General Information about an assembly is controlled through the following
8 | // set of attributes. Change these attribute values to modify the information
9 | // associated with an assembly.
10 | [assembly: AssemblyTitle("VncViewerLib.WPF")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("VncViewerLib.WPF")]
15 | [assembly: AssemblyCopyright("Copyright (C) 2008 David Humphrey; Copyright (C) 2011 Masanori Nakano; Copyright (C) 2018 Ricardo Brito")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // Setting ComVisible to false makes the types in this assembly not visible
20 | // to COM components. If you need to access a type in this assembly from
21 | // COM, set the ComVisible attribute to true on that type.
22 | [assembly: ComVisible(false)]
23 |
24 | //In order to begin building localizable applications, set
25 | //CultureYouAreCodingWith in your .csproj file
26 | //inside a . For example, if you are using US english
27 | //in your source files, set the to en-US. Then uncomment
28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in
29 | //the line below to match the UICulture setting in the project file.
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly:ThemeInfo(
35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
36 | //(used if a resource is not found in the page,
37 | // or application resource dictionaries)
38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
39 | //(used if a resource is not found in the page,
40 | // app, or any theme specific resource dictionaries)
41 | )]
42 |
43 |
44 | // Version information for an assembly consists of the following four values:
45 | //
46 | // Major Version
47 | // Minor Version
48 | // Build Number
49 | // Revision
50 | //
51 | // You can specify all the values or you can default the Build and Revision Numbers
52 | // by using the '*' as shown below:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 | [assembly: NeutralResourcesLanguage("en")]
57 |
58 |
--------------------------------------------------------------------------------
/VncViewer.WPF/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace VncViewer.WPF.Properties {
12 | using System;
13 |
14 |
15 | ///
16 | /// A strongly-typed resource class, for looking up localized strings, etc.
17 | ///
18 | // This class was auto-generated by the StronglyTypedResourceBuilder
19 | // class via a tool like ResGen or Visual Studio.
20 | // To add or remove a member, edit your .ResX file then rerun ResGen
21 | // with the /str option, or rebuild your VS project.
22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources {
26 |
27 | private static global::System.Resources.ResourceManager resourceMan;
28 |
29 | private static global::System.Globalization.CultureInfo resourceCulture;
30 |
31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
32 | internal Resources() {
33 | }
34 |
35 | ///
36 | /// Returns the cached ResourceManager instance used by this class.
37 | ///
38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
39 | internal static global::System.Resources.ResourceManager ResourceManager {
40 | get {
41 | if (object.ReferenceEquals(resourceMan, null)) {
42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("VncViewer.WPF.Properties.Resources", typeof(Resources).Assembly);
43 | resourceMan = temp;
44 | }
45 | return resourceMan;
46 | }
47 | }
48 |
49 | ///
50 | /// Overrides the current thread's CurrentUICulture property for all
51 | /// resource lookups using this strongly typed resource class.
52 | ///
53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
54 | internal static global::System.Globalization.CultureInfo Culture {
55 | get {
56 | return resourceCulture;
57 | }
58 | set {
59 | resourceCulture = value;
60 | }
61 | }
62 |
63 | ///
64 | /// Looks up a localized resource of type System.Byte[].
65 | ///
66 | internal static byte[] vnccursor {
67 | get {
68 | object obj = ResourceManager.GetObject("vnccursor", resourceCulture);
69 | return ((byte[])(obj));
70 | }
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/VncViewer.WPF/Properties/Resources.resx:
--------------------------------------------------------------------------------
1 |
2 |
3 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 | text/microsoft-resx
110 |
111 |
112 | 2.0
113 |
114 |
115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
116 |
117 |
118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
119 |
120 |
121 |
122 | ..\Resources\vnccursor.cur;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
123 |
124 |
--------------------------------------------------------------------------------
/VncViewer.WPF/Resources/vnccursor.cur:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/SilverCard/VncViewer/3f2229fa43c92991055fe468b50bc467d20c82a2/VncViewer.WPF/Resources/vnccursor.cur
--------------------------------------------------------------------------------
/VncViewer.WPF/VncViewerControl.xaml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/VncViewer.WPF/VncViewerControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Drawing;
3 | using System.ComponentModel;
4 | using System.Windows.Controls;
5 | using System.Windows.Media.Imaging;
6 | using System.Windows.Input;
7 | using System.Collections.Generic;
8 | using System.Windows;
9 | using System.Threading.Tasks;
10 | using VncViewer.Vnc;
11 | using VncViewer.WPF.Cultures;
12 |
13 | #pragma warning disable CA1305 // Specify IFormatProvider
14 |
15 | namespace VncViewer.WPF
16 | {
17 |
18 | [ToolboxBitmap(typeof(VncViewerControl), "Resources.vncviewer.ico")]
19 | public partial class VncViewerControl : UserControl, IDisposable
20 | {
21 |
22 | private VncClient _VncClient;
23 |
24 |
25 | public const String CursorName = "VncCursor";
26 | public Cursor VncCursor { get; private set; }
27 |
28 | public string Hostname { get => _VncClient?.Framebuffer?.Name; }
29 |
30 | public WriteableBitmap FramebufferBitmap { get; private set; }
31 | private WritableBitmapWriter _WritableBitmapWriter;
32 |
33 | #region Events
34 |
35 | public event EventHandler OnConnected;
36 | public event EventHandler OnDisconnected;
37 |
38 | #endregion
39 |
40 | public VncViewerControl() : base()
41 | {
42 | InitializeComponent();
43 | Cursor = ((TextBlock)this.Resources[CursorName]).Cursor;
44 | }
45 |
46 | public async Task ConnectAsync(String host, int port, byte bitsPerPixel, byte depth)
47 | {
48 | if (String.IsNullOrWhiteSpace(host)) throw new ArgumentException(Strings.HostInvalid, nameof(host));
49 |
50 | ShowLabelText(String.Format(Strings.ConnectingToHost, $"{host}:{port}" ));
51 |
52 | _VncClient?.Dispose();
53 | _VncClient = new VncClient(bitsPerPixel, depth);
54 | _VncClient.OnDisconnect += _VncClient_OnDisconnect;
55 | _VncClient.OnFramebufferUpdate += _VncClient_OnFramebufferUpdate;
56 |
57 | try
58 | {
59 | await Task.Run(() =>
60 | {
61 | _VncClient.Connect(host, port);
62 | }).ConfigureAwait(true);
63 | }
64 | catch (Exception ex)
65 | {
66 | ShowLabelText($"{Strings.FailedConnect}: {ex.Message}.");
67 | throw;
68 | }
69 |
70 | OnConnected?.Invoke(this, EventArgs.Empty);
71 | }
72 |
73 | public async Task VncAuthenticate(String password)
74 | {
75 | ShowLabelText($"{Strings.Authenticating}...");
76 |
77 | var a = new VncAuthenticator(password);
78 |
79 | try
80 | {
81 | await Task.Run(() => _VncClient.Authenticate(a)).ConfigureAwait(true);
82 | }
83 | catch (VncSecurityException ex)
84 | {
85 | ShowLabelText($"{Strings.AuthenticationFailed}: {ex.Reason}.");
86 | throw;
87 | }
88 |
89 | }
90 |
91 | private void _VncClient_OnDisconnect(VncClient sender, DisconnectEventArgs e)
92 | {
93 | OnDisconnected?.Invoke(this, EventArgs.Empty);
94 | }
95 |
96 | public async Task InitializeAsync()
97 | {
98 | ShowLabelText($"{Strings.Initializing}...");
99 | await Task.Run(() => _VncClient.Initialize()).ConfigureAwait(true);
100 |
101 | FramebufferBitmap = WritableBitmapWriter.BuildWriteableBitmap(_VncClient.Framebuffer.Width, _VncClient.Framebuffer.Height);
102 | VncImage.Source = FramebufferBitmap;
103 | _WritableBitmapWriter = new WritableBitmapWriter(FramebufferBitmap);
104 | _VncClient.ReceiveUpdates();
105 | }
106 |
107 | private void _VncClient_OnFramebufferUpdate(VncClient sender, FramebufferUpdateEventArgs e)
108 | {
109 | _WritableBitmapWriter.UpdateFromFramebuffer(e.Framebuffer, e.Rectangles);
110 | }
111 |
112 |
113 | public Task DisconnectAsync()
114 | {
115 | return Task.Run(() => _VncClient.Disconnect());
116 | }
117 |
118 | protected void VncClientConnectionLost(object sender, EventArgs e)
119 | {
120 | ShowLabelText($"{Strings.Disconnected}.");
121 | }
122 |
123 | public void ShowLabelText(String text)
124 | {
125 | Label.Content = text;
126 | Label.Visibility = Visibility.Visible;
127 | }
128 |
129 | public void HideLabel()
130 | {
131 | Label.Visibility = Visibility.Hidden;
132 | }
133 |
134 | #region IDisposable Support
135 | private bool disposedValue = false; // To detect redundant calls
136 |
137 | protected virtual void Dispose(bool disposing)
138 | {
139 | if (!disposedValue)
140 | {
141 | if (disposing)
142 | {
143 | _VncClient?.Dispose();
144 | }
145 |
146 | disposedValue = true;
147 | }
148 | }
149 |
150 |
151 |
152 | public void Dispose()
153 | {
154 | Dispose(true);
155 | GC.SuppressFinalize(this);
156 | }
157 | #endregion
158 |
159 | }
160 | }
161 |
--------------------------------------------------------------------------------
/VncViewer.WPF/WritableBitmapWriter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Drawing;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 | using System.Windows.Media.Imaging;
7 | using VncViewer.Vnc;
8 |
9 | namespace VncViewer.WPF
10 | {
11 | public class WritableBitmapWriter
12 | {
13 | public WriteableBitmap WriteableBitmap { get; private set; }
14 |
15 | public WritableBitmapWriter(WriteableBitmap writeableBitmap)
16 | {
17 | WriteableBitmap = writeableBitmap ?? throw new ArgumentNullException(nameof(writeableBitmap));
18 | }
19 |
20 | public static WriteableBitmap BuildWriteableBitmap(int width, int height)
21 | {
22 | if (width <= 0) throw new ArgumentOutOfRangeException(nameof(width));
23 | if (height <= 0) throw new ArgumentOutOfRangeException(nameof(height));
24 |
25 | var colors = new System.Windows.Media.Color[] {
26 | System.Windows.Media.Colors.Red,
27 | System.Windows.Media.Colors.Blue,
28 | System.Windows.Media.Colors.Green};
29 |
30 | var p = new BitmapPalette(colors);
31 | return new WriteableBitmap(width, height, 96, 96, System.Windows.Media.PixelFormats.Pbgra32, p);
32 | }
33 |
34 | ///
35 | /// Copy a rectangle from framebuffer into the bitmap's buffer.
36 | ///
37 | private static void CopyRectangle(IntPtr backBuffer, Framebuffer framebuffer, Rectangle r)
38 | {
39 | if (backBuffer == IntPtr.Zero) throw new ArgumentOutOfRangeException(nameof(backBuffer));
40 | if (framebuffer == null) throw new ArgumentNullException(nameof(framebuffer));
41 |
42 | for (int y = 0; y < r.Height; y++)
43 | {
44 | int idx = r.X + (r.Y + y) * framebuffer.Width;
45 | Marshal.Copy(framebuffer.PixelData, idx, backBuffer + 4 * idx, r.Width);
46 | }
47 | }
48 |
49 | ///
50 | /// Copy multiple rectangles from framebuffer into the bitmap.
51 | ///
52 | public void UpdateFromFramebuffer(Framebuffer f, IEnumerable rectangles)
53 | {
54 | if(f == null) throw new ArgumentNullException(nameof(f));
55 | if(rectangles == null) throw new ArgumentNullException(nameof(rectangles));
56 |
57 | IntPtr backBuffer = IntPtr.Zero;
58 |
59 | WriteableBitmap.Dispatcher.Invoke(() =>
60 | {
61 | WriteableBitmap.Lock();
62 | backBuffer = WriteableBitmap.BackBuffer;
63 | });
64 |
65 | foreach (var r in rectangles)
66 | {
67 | CopyRectangle(backBuffer, f, r);
68 | }
69 |
70 | WriteableBitmap.Dispatcher.Invoke(() =>
71 | {
72 | foreach (var r in rectangles)
73 | {
74 | WriteableBitmap.AddDirtyRect(new Int32Rect(r.X, r.Y, r.Width, r.Height));
75 | }
76 |
77 | WriteableBitmap.Unlock();
78 | });
79 | }
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/VncViewer.WPF/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------