Initial commit
This commit is contained in:
63
.gitattributes
vendored
Normal file
63
.gitattributes
vendored
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
###############################################################################
|
||||||
|
# Set default behavior to automatically normalize line endings.
|
||||||
|
###############################################################################
|
||||||
|
* text=auto
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Set default behavior for command prompt diff.
|
||||||
|
#
|
||||||
|
# This is need for earlier builds of msysgit that does not have it on by
|
||||||
|
# default for csharp files.
|
||||||
|
# Note: This is only used by command line
|
||||||
|
###############################################################################
|
||||||
|
#*.cs diff=csharp
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Set the merge driver for project and solution files
|
||||||
|
#
|
||||||
|
# Merging from the command prompt will add diff markers to the files if there
|
||||||
|
# are conflicts (Merging from VS is not affected by the settings below, in VS
|
||||||
|
# the diff markers are never inserted). Diff markers may cause the following
|
||||||
|
# file extensions to fail to load in VS. An alternative would be to treat
|
||||||
|
# these files as binary and thus will always conflict and require user
|
||||||
|
# intervention with every merge. To do so, just uncomment the entries below
|
||||||
|
###############################################################################
|
||||||
|
#*.sln merge=binary
|
||||||
|
#*.csproj merge=binary
|
||||||
|
#*.vbproj merge=binary
|
||||||
|
#*.vcxproj merge=binary
|
||||||
|
#*.vcproj merge=binary
|
||||||
|
#*.dbproj merge=binary
|
||||||
|
#*.fsproj merge=binary
|
||||||
|
#*.lsproj merge=binary
|
||||||
|
#*.wixproj merge=binary
|
||||||
|
#*.modelproj merge=binary
|
||||||
|
#*.sqlproj merge=binary
|
||||||
|
#*.wwaproj merge=binary
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# behavior for image files
|
||||||
|
#
|
||||||
|
# image files are treated as binary by default.
|
||||||
|
###############################################################################
|
||||||
|
#*.jpg binary
|
||||||
|
#*.png binary
|
||||||
|
#*.gif binary
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# diff behavior for common document formats
|
||||||
|
#
|
||||||
|
# Convert binary document formats to text before diffing them. This feature
|
||||||
|
# is only available from the command line. Turn it on by uncommenting the
|
||||||
|
# entries below.
|
||||||
|
###############################################################################
|
||||||
|
#*.doc diff=astextplain
|
||||||
|
#*.DOC diff=astextplain
|
||||||
|
#*.docx diff=astextplain
|
||||||
|
#*.DOCX diff=astextplain
|
||||||
|
#*.dot diff=astextplain
|
||||||
|
#*.DOT diff=astextplain
|
||||||
|
#*.pdf diff=astextplain
|
||||||
|
#*.PDF diff=astextplain
|
||||||
|
#*.rtf diff=astextplain
|
||||||
|
#*.RTF diff=astextplain
|
||||||
340
.gitignore
vendored
Normal file
340
.gitignore
vendored
Normal file
@@ -0,0 +1,340 @@
|
|||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
##
|
||||||
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.rsuser
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.userosscache
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# User-specific files (MonoDevelop/Xamarin Studio)
|
||||||
|
*.userprefs
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Dd]ebugPublic/
|
||||||
|
[Rr]elease/
|
||||||
|
[Rr]eleases/
|
||||||
|
x64/
|
||||||
|
x86/
|
||||||
|
[Aa][Rr][Mm]/
|
||||||
|
[Aa][Rr][Mm]64/
|
||||||
|
bld/
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
[Ll]og/
|
||||||
|
|
||||||
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
|
.vs/
|
||||||
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
|
#wwwroot/
|
||||||
|
|
||||||
|
# Visual Studio 2017 auto generated files
|
||||||
|
Generated\ Files/
|
||||||
|
|
||||||
|
# MSTest test Results
|
||||||
|
[Tt]est[Rr]esult*/
|
||||||
|
[Bb]uild[Ll]og.*
|
||||||
|
|
||||||
|
# NUNIT
|
||||||
|
*.VisualState.xml
|
||||||
|
TestResult.xml
|
||||||
|
|
||||||
|
# Build Results of an ATL Project
|
||||||
|
[Dd]ebugPS/
|
||||||
|
[Rr]eleasePS/
|
||||||
|
dlldata.c
|
||||||
|
|
||||||
|
# Benchmark Results
|
||||||
|
BenchmarkDotNet.Artifacts/
|
||||||
|
|
||||||
|
# .NET Core
|
||||||
|
project.lock.json
|
||||||
|
project.fragment.lock.json
|
||||||
|
artifacts/
|
||||||
|
|
||||||
|
# StyleCop
|
||||||
|
StyleCopReport.xml
|
||||||
|
|
||||||
|
# Files built by Visual Studio
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*_h.h
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.iobj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.ipdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.tmp_proj
|
||||||
|
*_wpftmp.csproj
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
*.pidb
|
||||||
|
*.svclog
|
||||||
|
*.scc
|
||||||
|
|
||||||
|
# Chutzpah Test files
|
||||||
|
_Chutzpah*
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opendb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
*.cachefile
|
||||||
|
*.VC.db
|
||||||
|
*.VC.VC.opendb
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
*.sap
|
||||||
|
|
||||||
|
# Visual Studio Trace Files
|
||||||
|
*.e2e
|
||||||
|
|
||||||
|
# TFS 2012 Local Workspace
|
||||||
|
$tf/
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*/
|
||||||
|
*.[Rr]e[Ss]harper
|
||||||
|
*.DotSettings.user
|
||||||
|
|
||||||
|
# JustCode is a .NET coding add-in
|
||||||
|
.JustCode
|
||||||
|
|
||||||
|
# TeamCity is a build add-in
|
||||||
|
_TeamCity*
|
||||||
|
|
||||||
|
# DotCover is a Code Coverage Tool
|
||||||
|
*.dotCover
|
||||||
|
|
||||||
|
# AxoCover is a Code Coverage Tool
|
||||||
|
.axoCover/*
|
||||||
|
!.axoCover/settings.json
|
||||||
|
|
||||||
|
# Visual Studio code coverage results
|
||||||
|
*.coverage
|
||||||
|
*.coveragexml
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
_NCrunch_*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
nCrunchTemp_*
|
||||||
|
|
||||||
|
# MightyMoose
|
||||||
|
*.mm.*
|
||||||
|
AutoTest.Net/
|
||||||
|
|
||||||
|
# Web workbench (sass)
|
||||||
|
.sass-cache/
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress/
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish/
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.[Pp]ublish.xml
|
||||||
|
*.azurePubxml
|
||||||
|
# Note: Comment the next line if you want to checkin your web deploy settings,
|
||||||
|
# but database connection strings (with potential passwords) will be unencrypted
|
||||||
|
*.pubxml
|
||||||
|
*.publishproj
|
||||||
|
|
||||||
|
# Microsoft Azure Web App publish settings. Comment the next line if you want to
|
||||||
|
# checkin your Azure Web App publish settings, but sensitive information contained
|
||||||
|
# in these scripts will be unencrypted
|
||||||
|
PublishScripts/
|
||||||
|
|
||||||
|
# NuGet Packages
|
||||||
|
*.nupkg
|
||||||
|
# The packages folder can be ignored because of Package Restore
|
||||||
|
**/[Pp]ackages/*
|
||||||
|
# except build/, which is used as an MSBuild target.
|
||||||
|
!**/[Pp]ackages/build/
|
||||||
|
# Uncomment if necessary however generally it will be regenerated when needed
|
||||||
|
#!**/[Pp]ackages/repositories.config
|
||||||
|
# NuGet v3's project.json files produces more ignorable files
|
||||||
|
*.nuget.props
|
||||||
|
*.nuget.targets
|
||||||
|
|
||||||
|
# Microsoft Azure Build Output
|
||||||
|
csx/
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Microsoft Azure Emulator
|
||||||
|
ecf/
|
||||||
|
rcf/
|
||||||
|
|
||||||
|
# Windows Store app package directories and files
|
||||||
|
AppPackages/
|
||||||
|
BundleArtifacts/
|
||||||
|
Package.StoreAssociation.xml
|
||||||
|
_pkginfo.txt
|
||||||
|
*.appx
|
||||||
|
|
||||||
|
# Visual Studio cache files
|
||||||
|
# files ending in .cache can be ignored
|
||||||
|
*.[Cc]ache
|
||||||
|
# but keep track of directories ending in .cache
|
||||||
|
!?*.[Cc]ache/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
ClientBin/
|
||||||
|
~$*
|
||||||
|
*~
|
||||||
|
*.dbmdl
|
||||||
|
*.dbproj.schemaview
|
||||||
|
*.jfm
|
||||||
|
*.pfx
|
||||||
|
*.publishsettings
|
||||||
|
orleans.codegen.cs
|
||||||
|
|
||||||
|
# Including strong name files can present a security risk
|
||||||
|
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
|
||||||
|
#*.snk
|
||||||
|
|
||||||
|
# Since there are multiple workflows, uncomment next line to ignore bower_components
|
||||||
|
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
|
||||||
|
#bower_components/
|
||||||
|
|
||||||
|
# RIA/Silverlight projects
|
||||||
|
Generated_Code/
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file
|
||||||
|
# to a newer Visual Studio version. Backup files are not needed,
|
||||||
|
# because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
||||||
|
UpgradeLog*.htm
|
||||||
|
ServiceFabricBackup/
|
||||||
|
*.rptproj.bak
|
||||||
|
|
||||||
|
# SQL Server files
|
||||||
|
*.mdf
|
||||||
|
*.ldf
|
||||||
|
*.ndf
|
||||||
|
|
||||||
|
# Business Intelligence projects
|
||||||
|
*.rdl.data
|
||||||
|
*.bim.layout
|
||||||
|
*.bim_*.settings
|
||||||
|
*.rptproj.rsuser
|
||||||
|
*- Backup*.rdl
|
||||||
|
|
||||||
|
# Microsoft Fakes
|
||||||
|
FakesAssemblies/
|
||||||
|
|
||||||
|
# GhostDoc plugin setting file
|
||||||
|
*.GhostDoc.xml
|
||||||
|
|
||||||
|
# Node.js Tools for Visual Studio
|
||||||
|
.ntvs_analysis.dat
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Visual Studio 6 build log
|
||||||
|
*.plg
|
||||||
|
|
||||||
|
# Visual Studio 6 workspace options file
|
||||||
|
*.opt
|
||||||
|
|
||||||
|
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
|
||||||
|
*.vbw
|
||||||
|
|
||||||
|
# Visual Studio LightSwitch build output
|
||||||
|
**/*.HTMLClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/GeneratedArtifacts
|
||||||
|
**/*.DesktopClient/ModelManifest.xml
|
||||||
|
**/*.Server/GeneratedArtifacts
|
||||||
|
**/*.Server/ModelManifest.xml
|
||||||
|
_Pvt_Extensions
|
||||||
|
|
||||||
|
# Paket dependency manager
|
||||||
|
.paket/paket.exe
|
||||||
|
paket-files/
|
||||||
|
|
||||||
|
# FAKE - F# Make
|
||||||
|
.fake/
|
||||||
|
|
||||||
|
# JetBrains Rider
|
||||||
|
.idea/
|
||||||
|
*.sln.iml
|
||||||
|
|
||||||
|
# CodeRush personal settings
|
||||||
|
.cr/personal
|
||||||
|
|
||||||
|
# Python Tools for Visual Studio (PTVS)
|
||||||
|
__pycache__/
|
||||||
|
*.pyc
|
||||||
|
|
||||||
|
# Cake - Uncomment if you are using it
|
||||||
|
# tools/**
|
||||||
|
# !tools/packages.config
|
||||||
|
|
||||||
|
# Tabs Studio
|
||||||
|
*.tss
|
||||||
|
|
||||||
|
# Telerik's JustMock configuration file
|
||||||
|
*.jmconfig
|
||||||
|
|
||||||
|
# BizTalk build output
|
||||||
|
*.btp.cs
|
||||||
|
*.btm.cs
|
||||||
|
*.odx.cs
|
||||||
|
*.xsd.cs
|
||||||
|
|
||||||
|
# OpenCover UI analysis results
|
||||||
|
OpenCover/
|
||||||
|
|
||||||
|
# Azure Stream Analytics local run output
|
||||||
|
ASALocalRun/
|
||||||
|
|
||||||
|
# MSBuild Binary and Structured Log
|
||||||
|
*.binlog
|
||||||
|
|
||||||
|
# NVidia Nsight GPU debugger configuration file
|
||||||
|
*.nvuser
|
||||||
|
|
||||||
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
|
.mfractor/
|
||||||
|
|
||||||
|
# Local History for Visual Studio
|
||||||
|
.localhistory/
|
||||||
|
|
||||||
|
# BeatPulse healthcheck temp database
|
||||||
|
healthchecksdb
|
||||||
37
SyncProfilePicture.sln
Normal file
37
SyncProfilePicture.sln
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.31005.135
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyncProfilePicture", "SyncProfilePicture\SyncProfilePicture.csproj", "{B55493BD-5C1D-4426-A725-4C3880884039}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Debug|x64 = Debug|x64
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
Release|x64 = Release|x64
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Debug|x64.Build.0 = Debug|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Release|x64.ActiveCfg = Release|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Release|x64.Build.0 = Release|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{B55493BD-5C1D-4426-A725-4C3880884039}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {7DC3CFB0-52C5-47DF-AFF0-84B5679A9108}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
6
SyncProfilePicture/App.config
Normal file
6
SyncProfilePicture/App.config
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<startup>
|
||||||
|
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
|
||||||
|
</startup>
|
||||||
|
</configuration>
|
||||||
313
SyncProfilePicture/Program.cs
Normal file
313
SyncProfilePicture/Program.cs
Normal file
@@ -0,0 +1,313 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.DirectoryServices;
|
||||||
|
using System.IO;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
using System.Security.Principal;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
|
||||||
|
namespace SyncProfilePicture
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public static void SetLocal(Image image, string userSid, string profilePictureFolder, bool doVerbose)
|
||||||
|
{
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Creating folder " + profilePictureFolder);
|
||||||
|
}
|
||||||
|
DirectoryInfo newFolder = Directory.CreateDirectory(profilePictureFolder);
|
||||||
|
newFolder.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
|
||||||
|
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Setting registry key HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AccountPicture\\Users\\{userSid}");
|
||||||
|
}
|
||||||
|
RegistryKey localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
|
||||||
|
RegistryKey userKey = localMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AccountPicture\\Users", RegistryKeyPermissionCheck.ReadWriteSubTree);
|
||||||
|
userKey.CreateSubKey(userSid);
|
||||||
|
RegistryKey sidKey = userKey.OpenSubKey(userSid, RegistryKeyPermissionCheck.ReadWriteSubTree);
|
||||||
|
List<string> imageSizes = new List<string>
|
||||||
|
{
|
||||||
|
"1080",
|
||||||
|
"192",
|
||||||
|
"208",
|
||||||
|
"240",
|
||||||
|
"32",
|
||||||
|
"40",
|
||||||
|
"424",
|
||||||
|
"448",
|
||||||
|
"48",
|
||||||
|
"64",
|
||||||
|
"96"
|
||||||
|
};
|
||||||
|
foreach (string imageSize in imageSizes)
|
||||||
|
{
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Saving profile picture to {profilePictureFolder}\\{userSid}-Image{imageSize}.jpg");
|
||||||
|
}
|
||||||
|
Int32 imageSizeInt = Int32.Parse(imageSize);
|
||||||
|
sidKey.SetValue($"Image{imageSize}", $"{profilePictureFolder}\\{userSid}-Image{imageSize}.jpg");
|
||||||
|
Image imageResized = new Bitmap(image, new Size(imageSizeInt, imageSizeInt));
|
||||||
|
imageResized.Save($"{profilePictureFolder}\\{userSid}-Image{imageSize}.jpg", ImageFormat.Jpeg);
|
||||||
|
};
|
||||||
|
sidKey.Close();
|
||||||
|
userKey.Close();
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Local profile picture set.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static string ShrinkImage(string path)
|
||||||
|
{
|
||||||
|
Image image = Image.FromFile(path);
|
||||||
|
string newPath = path;
|
||||||
|
double fileSize = new FileInfo(path).Length / 1024;
|
||||||
|
int oldHeight = image.Height;
|
||||||
|
while (fileSize > 100) {
|
||||||
|
if (path != newPath)
|
||||||
|
{
|
||||||
|
File.Delete(newPath);
|
||||||
|
}
|
||||||
|
int newHeight = (Int32)(oldHeight * 0.9);
|
||||||
|
Image newImage = new Bitmap(image, new Size(newHeight, newHeight));
|
||||||
|
newPath = $"{Path.GetTempPath()}\\{Path.GetFileNameWithoutExtension(path)}-{newHeight}.jpg";
|
||||||
|
newImage.Save(newPath, ImageFormat.Jpeg);
|
||||||
|
fileSize = new FileInfo(newPath).Length / 1024;
|
||||||
|
oldHeight = newHeight;
|
||||||
|
}
|
||||||
|
return newPath;
|
||||||
|
}
|
||||||
|
public static void SetAd(string profilePicturePath, DirectoryEntry userEntry, string userAttribute, bool doVerbose)
|
||||||
|
{
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Using picture file {profilePicturePath}");
|
||||||
|
}
|
||||||
|
Image profilePicture = Image.FromFile(profilePicturePath);
|
||||||
|
double fileSizeKB = new FileInfo(profilePicturePath).Length / 1024;
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Profile picture size is {fileSizeKB}KB");
|
||||||
|
}
|
||||||
|
if (fileSizeKB > 100)
|
||||||
|
{
|
||||||
|
profilePicturePath = ShrinkImage(profilePicturePath);
|
||||||
|
profilePicture = Image.FromFile(profilePicturePath);
|
||||||
|
fileSizeKB = new FileInfo(profilePicturePath).Length / 1024;
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Profile picture resized, using {profilePicturePath}");
|
||||||
|
Console.WriteLine($"Profile picture size is {fileSizeKB}KB");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
var ms = new MemoryStream();
|
||||||
|
profilePicture.Save(ms, profilePicture.RawFormat);
|
||||||
|
var profilePictureArray = ms.ToArray();
|
||||||
|
userEntry.Properties[userAttribute].Clear();
|
||||||
|
userEntry.CommitChanges();
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("AD profile picture cleared.");
|
||||||
|
}
|
||||||
|
userEntry.Properties[userAttribute].Add(profilePictureArray);
|
||||||
|
userEntry.CommitChanges();
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("AD profile picture updated.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
//defaults
|
||||||
|
string pictureSize = "1080";
|
||||||
|
string userAttribute = "thumbnailPhoto";
|
||||||
|
bool doAdToLocal = false;
|
||||||
|
bool doLocalToAd = false;
|
||||||
|
bool doVerbose = false;
|
||||||
|
bool doFileToLocal = false;
|
||||||
|
bool doAdToFile = false;
|
||||||
|
bool doOtherUser = false;
|
||||||
|
bool doFileToAd = false;
|
||||||
|
string importPicturePath = null;
|
||||||
|
string exportPicturePath = null;
|
||||||
|
string userName = null;
|
||||||
|
string userSid = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < args.Length; i++)
|
||||||
|
{
|
||||||
|
if (String.Equals(args[i], "-username"))
|
||||||
|
{
|
||||||
|
|
||||||
|
doOtherUser = true;
|
||||||
|
userName = args[(i + 1)];
|
||||||
|
|
||||||
|
}
|
||||||
|
if (String.Equals(args[i], "-file2local"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Setting AD profile picture from file.");
|
||||||
|
doFileToLocal = true;
|
||||||
|
importPicturePath = args[(i + 1)];
|
||||||
|
|
||||||
|
}
|
||||||
|
if (String.Equals(args[i], "-file2ad"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Setting local profile picture from file.");
|
||||||
|
doFileToAd = true;
|
||||||
|
importPicturePath = args[(i + 1)];
|
||||||
|
|
||||||
|
}
|
||||||
|
if (String.Equals(args[i], "-ad2file"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Exporting profile picture from AD to file.");
|
||||||
|
doAdToFile = true;
|
||||||
|
exportPicturePath = args[(i + 1)];
|
||||||
|
|
||||||
|
}
|
||||||
|
if (String.Equals(args[i], "-verbose"))
|
||||||
|
{
|
||||||
|
Console.WriteLine("Verbose messages selected.");
|
||||||
|
doVerbose = true;
|
||||||
|
}
|
||||||
|
if (String.Equals( args[i], "-ad2local"))
|
||||||
|
{
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Saving profile picture from AD to local");
|
||||||
|
}
|
||||||
|
doAdToLocal = true;
|
||||||
|
}
|
||||||
|
if (String.Equals(args[i], "-local2ad"))
|
||||||
|
{
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Saving profile picture from local to AD");
|
||||||
|
}
|
||||||
|
doLocalToAd = true;
|
||||||
|
}
|
||||||
|
if (String.Equals(args[i], "-jpegPhoto"))
|
||||||
|
{
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Using jpegPhoto as AD user attribute");
|
||||||
|
}
|
||||||
|
userAttribute = "jpegPhoto";
|
||||||
|
}
|
||||||
|
if (String.Equals(args[i], "-picturesize"))
|
||||||
|
{
|
||||||
|
pictureSize = args[(i + 1)];
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Using picture size {pictureSize}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (doAdToLocal & doLocalToAd)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Error: both -ad2local and -local2ad used. Choose only one option");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!doAdToLocal & !doLocalToAd & !doFileToLocal & !doAdToFile & !doFileToAd)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Usage:\r\nSyncProfilePicture [-ad2local | -local2ad | -file2local | -ad2file] [-picturesize <size>] [-username <Active Directory username>] [-jpegPhoto] [-verbose]");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Connect to AD
|
||||||
|
DirectoryEntry RootDirEntry = new DirectoryEntry("LDAP://RootDSE");
|
||||||
|
var distinguishedName = RootDirEntry.Properties["defaultNamingContext"].Value;
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Using ActiveDirectory domain " + distinguishedName);
|
||||||
|
}
|
||||||
|
var myDE = new DirectoryEntry("LDAP://" + distinguishedName);
|
||||||
|
if (!doOtherUser)
|
||||||
|
{
|
||||||
|
userName = Environment.UserName;
|
||||||
|
}
|
||||||
|
DirectorySearcher directorySearcher = new DirectorySearcher(myDE, String.Format("(sAMAccountName={0})", userName));
|
||||||
|
SearchResult searchResult = directorySearcher.FindOne();
|
||||||
|
DirectoryEntry userEntry = searchResult.GetDirectoryEntry();
|
||||||
|
|
||||||
|
//Find username & SID
|
||||||
|
if (!doOtherUser)
|
||||||
|
{
|
||||||
|
userSid = System.Security.Principal.WindowsIdentity.GetCurrent().User.Value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
userSid = new SecurityIdentifier((byte[])userEntry.Properties["objectSid"].Value, 0).ToString();
|
||||||
|
}
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Using username " + userName);
|
||||||
|
Console.WriteLine("using SID " + userSid);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string profilePictureFolder = $"{Environment.GetEnvironmentVariable("Public")}\\AccountPictures\\{userSid}";
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("using profile picture folder " + profilePictureFolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (doAdToLocal)
|
||||||
|
{
|
||||||
|
var jpegByteArray = userEntry.Properties[userAttribute].Value;
|
||||||
|
Image image = (Bitmap)((new ImageConverter()).ConvertFrom(jpegByteArray));
|
||||||
|
SetLocal(image, userSid, profilePictureFolder, doVerbose);
|
||||||
|
}
|
||||||
|
if (doAdToFile)
|
||||||
|
{
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Saving AD profile picture to " + exportPicturePath);
|
||||||
|
}
|
||||||
|
var jpegByteArray = userEntry.Properties[userAttribute].Value;
|
||||||
|
Image image = (Bitmap)((new ImageConverter()).ConvertFrom(jpegByteArray));
|
||||||
|
image.Save(exportPicturePath, ImageFormat.Jpeg);
|
||||||
|
}
|
||||||
|
if (doFileToLocal)
|
||||||
|
{
|
||||||
|
if (File.Exists(importPicturePath))
|
||||||
|
{
|
||||||
|
Image image = Image.FromFile(importPicturePath);
|
||||||
|
SetLocal(image, userSid, profilePictureFolder, doVerbose);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error: {importPicturePath} not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (doFileToAd)
|
||||||
|
{
|
||||||
|
if (File.Exists(importPicturePath))
|
||||||
|
{
|
||||||
|
Image image = Image.FromFile(importPicturePath);
|
||||||
|
SetAd(importPicturePath, userEntry, userAttribute, doVerbose);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error: {importPicturePath} not found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (doLocalToAd)
|
||||||
|
{
|
||||||
|
RegistryKey localMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
|
||||||
|
RegistryKey userKey = localMachine.OpenSubKey($"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AccountPicture\\Users\\{userSid}", RegistryKeyPermissionCheck.ReadWriteSubTree);
|
||||||
|
string profilePicturePath = (string)userKey.GetValue($"Image{pictureSize}");
|
||||||
|
SetAd(profilePicturePath, userEntry, userAttribute, doVerbose);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (doVerbose)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Done.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
SyncProfilePicture/Properties/AssemblyInfo.cs
Normal file
36
SyncProfilePicture/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
// General Information about an assembly is controlled through the following
|
||||||
|
// set of attributes. Change these attribute values to modify the information
|
||||||
|
// associated with an assembly.
|
||||||
|
[assembly: AssemblyTitle("SyncProfilePicture")]
|
||||||
|
[assembly: AssemblyDescription("Sunc AD thumbnailPhoto to Windows 10 Profile Picture")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Thomas de Roo")]
|
||||||
|
[assembly: AssemblyProduct("SyncProfilePicture")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © 2021")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// Setting ComVisible to false makes the types in this assembly not visible
|
||||||
|
// to COM components. If you need to access a type in this assembly from
|
||||||
|
// COM, set the ComVisible attribute to true on that type.
|
||||||
|
[assembly: ComVisible(false)]
|
||||||
|
|
||||||
|
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||||
|
[assembly: Guid("b55493bd-5c1d-4426-a725-4c3880884039")]
|
||||||
|
|
||||||
|
// Version information for an assembly consists of the following four values:
|
||||||
|
//
|
||||||
|
// Major Version
|
||||||
|
// Minor Version
|
||||||
|
// Build Number
|
||||||
|
// Revision
|
||||||
|
//
|
||||||
|
// You can specify all the values or you can default the Build and Revision Numbers
|
||||||
|
// by using the '*' as shown below:
|
||||||
|
// [assembly: AssemblyVersion("1.0.*")]
|
||||||
|
[assembly: AssemblyVersion("21.7.9.0")]
|
||||||
|
[assembly: AssemblyFileVersion("21.7.9.0")]
|
||||||
26
SyncProfilePicture/Properties/Settings.Designer.cs
generated
Normal file
26
SyncProfilePicture/Properties/Settings.Designer.cs
generated
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was generated by a tool.
|
||||||
|
// Runtime Version:4.0.30319.42000
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
namespace SyncProfilePicture.Properties {
|
||||||
|
|
||||||
|
|
||||||
|
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||||
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.8.1.0")]
|
||||||
|
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
|
||||||
|
|
||||||
|
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
|
||||||
|
|
||||||
|
public static Settings Default {
|
||||||
|
get {
|
||||||
|
return defaultInstance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
SyncProfilePicture/Properties/Settings.settings
Normal file
6
SyncProfilePicture/Properties/Settings.settings
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
|
||||||
|
<Profiles>
|
||||||
|
<Profile Name="(Default)" />
|
||||||
|
</Profiles>
|
||||||
|
</SettingsFile>
|
||||||
102
SyncProfilePicture/SyncProfilePicture.csproj
Normal file
102
SyncProfilePicture/SyncProfilePicture.csproj
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
|
<ProjectGuid>{B55493BD-5C1D-4426-A725-4C3880884039}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RootNamespace>SyncProfilePicture</RootNamespace>
|
||||||
|
<AssemblyName>SyncProfilePicture</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||||
|
<FileAlignment>512</FileAlignment>
|
||||||
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
|
<Deterministic>true</Deterministic>
|
||||||
|
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||||
|
<PublishUrl>publish\</PublishUrl>
|
||||||
|
<Install>true</Install>
|
||||||
|
<InstallFrom>Disk</InstallFrom>
|
||||||
|
<UpdateEnabled>false</UpdateEnabled>
|
||||||
|
<UpdateMode>Foreground</UpdateMode>
|
||||||
|
<UpdateInterval>7</UpdateInterval>
|
||||||
|
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||||
|
<UpdatePeriodically>false</UpdatePeriodically>
|
||||||
|
<UpdateRequired>false</UpdateRequired>
|
||||||
|
<MapFileExtensions>true</MapFileExtensions>
|
||||||
|
<ApplicationRevision>0</ApplicationRevision>
|
||||||
|
<ApplicationVersion>0.1.210709.0</ApplicationVersion>
|
||||||
|
<UseApplicationTrust>false</UseApplicationTrust>
|
||||||
|
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||||
|
<NuGetPackageImportStamp>
|
||||||
|
</NuGetPackageImportStamp>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
|
<DebugType>pdbonly</DebugType>
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<StartupObject>SyncProfilePicture.Program</StartupObject>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ApplicationIcon>SyncProfilePicture.ico</ApplicationIcon>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
<Reference Include="System.Core" />
|
||||||
|
<Reference Include="System.DirectoryServices" />
|
||||||
|
<Reference Include="System.Drawing" />
|
||||||
|
<Reference Include="System.Xml.Linq" />
|
||||||
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
|
<Reference Include="Microsoft.CSharp" />
|
||||||
|
<Reference Include="System.Data" />
|
||||||
|
<Reference Include="System.Net.Http" />
|
||||||
|
<Reference Include="System.Xml" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Properties\Settings.Designer.cs">
|
||||||
|
<AutoGen>True</AutoGen>
|
||||||
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
|
<DependentUpon>Settings.settings</DependentUpon>
|
||||||
|
</Compile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<None Include="App.config" />
|
||||||
|
<None Include="Properties\Settings.settings">
|
||||||
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>Microsoft .NET Framework 4.7.2 %28x86 and x64%29</ProductName>
|
||||||
|
<Install>true</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||||
|
<Visible>False</Visible>
|
||||||
|
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||||
|
<Install>false</Install>
|
||||||
|
</BootstrapperPackage>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="SyncProfilePicture.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
BIN
SyncProfilePicture/SyncProfilePicture.ico
Normal file
BIN
SyncProfilePicture/SyncProfilePicture.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 103 KiB |
Reference in New Issue
Block a user