コード例 #1
0
ファイル: Processor.cs プロジェクト: manse/LIP2GIF
		/**
		 * 監視・変換処理を開始する
		 */
		public async void Start() {
			NotifyIcon icon = ShowNotificationIcon();
			String path = ChooseTargetFilePath();
			if (path == null) {
				icon.Visible = false;
				System.Threading.Thread.CurrentThread.Abort();
				return;
			}

			// クリスタが起動していない場合は起動を待つ
			// (クリスタの終了をトリガにしてGIFを作成するため)
			System.Diagnostics.Process.Start(path);
			while (!IsClipStudioPaintRunning()) System.Threading.Thread.Sleep(1000);

			String tmpDir = path + "$" + APP_NAME + @"\";
			Directory.CreateDirectory(tmpDir);

			// 画像の更新日時が変わっていたらプレビュー画像を書き出す(クリスタが終了するまで繰り返し)
			String lastImageSize = "";
			while (IsClipStudioPaintRunning()) {
				String imageSize = "";
				try {
					imageSize = new FileInfo(path).LastWriteTime.ToString();
				} catch (Exception e) { }
				if (imageSize != "" && imageSize != lastImageSize) {
					byte[] pngBytes = new byte[0];
					try {
						pngBytes = GetPNGDataFromLIP(path);
					} catch (Exception e) {
					}
					if (pngBytes.Length != 0) {
						File.WriteAllBytes(tmpDir + @"\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png", pngBytes);
						icon.Icon = GenerateCounterIcon(Directory.GetFiles(tmpDir).Length);
						lastImageSize = imageSize;
					}
				}
				System.Threading.Thread.Sleep(1000);
			}

			// GIFアニメーションを生成
			icon.Visible = false;
			ProcessDialog dialog = new ProcessDialog();
			String dstPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), APP_NAME + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".gif");
			dialog.Show();
			await Task.Run(() => {
				GenerateAnimationGIF(tmpDir, dstPath);
			});
			dialog.Hide();

			// キャッシュを削除
			foreach (String file in Directory.GetFiles(tmpDir)) {
				File.SetAttributes(file, FileAttributes.Normal);
				File.Delete(file);
			}
			Directory.Delete(tmpDir);

			if (File.Exists(dstPath)) {
				System.Diagnostics.Process.Start("explorer.exe", "/select, " + dstPath);
			}
			Application.Exit();
		}
コード例 #2
0
ファイル: Processor.cs プロジェクト: PettyBell/LIP2GIF
        /**
         * 監視・変換処理を開始する
         */
        public async void Start()
        {
            NotifyIcon icon = ShowNotificationIcon();
            String     path = ChooseTargetFilePath();

            if (path == null)
            {
                icon.Visible = false;
                System.Threading.Thread.CurrentThread.Abort();
                return;
            }

            // クリスタが起動していない場合は起動を待つ
            // (クリスタの終了をトリガにしてGIFを作成するため)
            System.Diagnostics.Process.Start(path);
            while (!IsClipStudioPaintRunning())
            {
                System.Threading.Thread.Sleep(1000);
            }

            String tmpDir = path + "$" + APP_NAME + @"\";

            Directory.CreateDirectory(tmpDir);

            // 画像の更新日時が変わっていたらプレビュー画像を書き出す(クリスタが終了するまで繰り返し)
            String lastImageSize = "";

            while (IsClipStudioPaintRunning())
            {
                String imageSize = "";
                try {
                    imageSize = new FileInfo(path).LastWriteTime.ToString();
                } catch (Exception e) { }
                if (imageSize != "" && imageSize != lastImageSize)
                {
                    byte[] pngBytes = new byte[0];
                    try {
                        pngBytes = GetPNGDataFromLIP(path);
                    } catch (Exception e) {
                    }
                    if (pngBytes.Length != 0)
                    {
                        File.WriteAllBytes(tmpDir + @"\" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".png", pngBytes);
                        icon.Icon     = GenerateCounterIcon(Directory.GetFiles(tmpDir).Length);
                        lastImageSize = imageSize;
                    }
                }
                System.Threading.Thread.Sleep(1000);
            }

            // GIFアニメーションを生成
            icon.Visible = false;
            ProcessDialog dialog  = new ProcessDialog();
            String        dstPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), APP_NAME + "_" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".gif");

            dialog.Show();
            await Task.Run(() => {
                GenerateAnimationGIF(tmpDir, dstPath);
            });

            dialog.Hide();

            // キャッシュを削除
            foreach (String file in Directory.GetFiles(tmpDir))
            {
                File.SetAttributes(file, FileAttributes.Normal);
                File.Delete(file);
            }
            Directory.Delete(tmpDir);

            if (File.Exists(dstPath))
            {
                System.Diagnostics.Process.Start("explorer.exe", "/select, " + dstPath);
            }
            Application.Exit();
        }