Skip to content

Instantly share code, notes, and snippets.

View Tocchann's full-sized avatar

Toshiyuki Takahagi Tocchann

View GitHub Profile
@Tocchann
Tocchann / VersionSetup.targets
Last active April 19, 2025 07:41
csproj, vcxproj で実際にバージョンを自動更新するための定義(SetupFileVersion.ps1とセットで使うw)
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- FileVersion と、StartYear はあらかじめターゲットのプロジェクトで設定しておくこと -->
<Target Name="ValidateNeedGenerateVersionProperties">
<Error Condition="'$(StartYear)' == ''" Text="プロパティ 'StartYear' が定義されていません。" />
<Error Condition="'$(Version)' == '' and '$(FileVersion)' == ''" Text="プロパティ 'Version' か 'FileVersion' の定義が必要です。" />
</Target>
<!--ビルド済みのバージョン情報を取得して、新しいバージョンを定義する PowerShell スクリプト。アウトプットを Item として取り込む-->
<Target Name="GenerateVersionDetail">
<PropertyGroup>
@Tocchann
Tocchann / SetupFileVersion.ps1
Last active April 15, 2025 14:36
.csproj .vcxproj でビルド時自動インクリメントをサポートするためのスクリプト
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]$TargetPath,
[Parameter(Mandatory=$true)]
[int]$StartYear,
[Parameter(Mandatory=$true)]
[string]$BaseVersionStr
)
@Tocchann
Tocchann / Init-VsDevShell.ps1
Created September 24, 2024 06:11
PowerShellのコマンド内でコンソール版devenv を呼び出せるようにする初期化処理(常に最新バージョンを利用する形式)
function Init-VsDevShell
{
# 現在インストールされている Visual Studio の情報を取得するためのコマンドラインツールの存在をチェック
$vswherePath = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio" "Installer" "vswhere.exe"
if( -not (Test-Path $vswherePath) ){
Write-Error "VisualStudio がインストールされていません"
exit 1
}
# 特定のバージョンを利用したい場合は、-latest の代わりに -version "[17.0,18.0)" のように特定1バージョンとなるように設定を行う
# 複数エディションをインストールしている場合は考慮していないので要注意
@Tocchann
Tocchann / IsoImage.cs
Created March 11, 2024 07:59
IMAPI2を使ってISOイメージを保存
using System;
public class IsoImage
{
// 固定値(自動判定)
private const int mediaBlockSize = 2048;
private const long maxSizeDVD = 4488L * 512 * mediaBlockSize;
private const long maxSizeCD = 650L * 512 * mediaBlockSize;
public string SourceImageFolder { get; set; }
@Tocchann
Tocchann / NativeMethods.GetSafeOwnerWindow.cs
Last active September 16, 2023 08:24
WPF で Windows API のオーナーウィンドウとして渡すハンドルを取得する
using System;
using System.Runtime.InteropServices;
using System.Windows;
namespace Tocchann.Interop;
public static class NativeMethods
{
public static IntPtr GetSafeOwnerWindow( Window? ownerWindow )
{
@Tocchann
Tocchann / Utilities.GetOwnerWindow.cs
Created September 16, 2023 08:10
WPF でポップアップに渡すべきオーナーウィンドウにできる System.Windows.Window を取得する
using System.Windows;
namespace Tocchann;
public static class Utilities
{
public static Window? GetOwnerWindow()
{
var window = default(Window);
foreach( Window search in Application.Current.Windows )
{
@Tocchann
Tocchann / MyApp.cpp
Created September 12, 2023 16:48
AfxMessageBox をこっそり TaskDialog にして、HighDPI 対応するおまじない実装
int CMyApp::DoMessageBox( LPCTSTR lpszPrompt, UINT nType, UINT nIDPrompt )
{
// アイコンを整理しておく
if( (nType & MB_ICONMASK) == 0 )
{
switch( nType & MB_TYPEMASK )
{
case MB_OK:
case MB_OKCANCEL:
nType |= MB_ICONEXCLAMATION;
@Tocchann
Tocchann / RelayCommand.cs
Created March 31, 2022 11:23
ICommand のミニマムベースクラス
using System;
using System.Diagnostics;
using System.Windows.Input;
namespace SimpleMVVM
{
public class RelayCommand : ICommand
{
private readonly Action<object> execute;
private readonly Predicate<object> canExecute;
@Tocchann
Tocchann / StdinPipe.ps1
Created February 6, 2022 08:39
PowerShellスクリプトでパイプ処理
# StdinPipe.ps1 [-InputObject] <string[]> [-ReqireParam] <string> [[-OptionalParam] <string>] [<CommonParameters>]
[CmdletBinding()]
param (
[parameter(Mandatory=$true,ValueFromPipeline=$true,HelpMessage="標準入力か引数で受け取るデータ")]
[string[]]$InputObject,
[parameter(Mandatory=$true,ValueFromPipeline=$false,HelpMessage="必須パラメータ")]
[string]$ReqireParam,
[parameter(Mandatory=$false,ValueFromPipeline=$false,HelpMessage="オプションパラメータ")]
[string]$OptionalParam
)
@Tocchann
Tocchann / ParallelRendering.cs
Last active November 23, 2021 15:31
レンダリング丸ごと並列化
// 排他制御せずにレンダリングしてもらう(メモリイータータイプ)
private ImageSource CreateThumbnail( stirng filePath, Cube.Pdf.Page page )
{
using( var renderer = new DocumentRenderer( filePath ) )
using( var image = renderer.Render( page, page.Size ) )
using( var stream = new MemoryStream() )
{
image.Save( stream, ImageFormat.png );
stream.Seek( 0, SeekOrigin.Begin );
return BitmapFrame( stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad );