예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (!finishInit)
            {
                var authenticated = false;
                if (!string.IsNullOrEmpty(accessToken) && !string.IsNullOrEmpty(accessSecret))
                {
                    tweeetToken = Tokens.Create(apiKey, apiSecret, accessToken, accessSecret);
                    var response = tweeetToken.Account.VerifyCredentials();
                    tweeetToken.UserId      = response.Id.Value;
                    tweeetToken.ScreenName  = response.ScreenName;
                    metroPanel8.Enabled     = true;
                    labelTwitterUserID.Text = "@" + tweeetToken.ScreenName;
                    authenticated           = true;
                    try
                    {
                    }
                    catch (Exception ex)
                    {
                        LogOutput(ex.ToString());
                    }
                }
                if (!authenticated)
                {
                    tweeetToken             = null;
                    accessToken             = "";
                    accessSecret            = "";
                    metroPanel8.Enabled     = false;
                    labelTwitterUserID.Text = "未認証";
                }

                //監視を開始する
                fileSystemWatcher.EnableRaisingEvents = settingsObserveSS.Checked;
                fileListBindingSource.DataSource      = fileItems;
                metroGrid1.DataSource = fileListBindingSource;
                gridPRSSTagList.AutoGenerateColumns = false;
                tagListBindingSource.DataSource     = tagItems;
                gridPRSSTagList.DataSource          = tagListBindingSource;
                gridNSSTagList.AutoGenerateColumns  = false;
                gridNSSTagList.DataSource           = tagListBindingSource;
                tagSelectorBindingSource.DataSource = tagItems;
                metroComboBox2.DataSource           = tagSelectorBindingSource;
                gridTweetHashtagList.DataSource     = hashTagItems;
                currentDirectory = GetSSFolderPath();
                LoadRecentlyImage(lastFilePath, false);
                LoadPreviewImage(null);
                finishInit = true;

                Task.Factory.StartNew(async() =>
                {
                    await Task.Delay(100);
                    this.Invoke((MethodInvoker)(() =>
                    {
                        listViewTweetImage.BackColor = this.BackColor;
                        listViewTweetQueue.BackColor = this.BackColor;
                        CheckNewMessage();
                        if (IsSSFolderLinked())
                        {
                            var srcPath = settingsFolderLinkSrc.FilePath;
                            var destPath = settingsFolderLinkDest.FilePath;
                            LoadPreviewImage(null);
                            LoadRecentlyImage(null);
                            var files = Directory.GetFiles(srcPath, "*.png", SearchOption.AllDirectories);
                            var dialog = new ProgressWindow(metroStyleManager1);
                            dialog.Title = "スクリーンショット移動中...";
                            dialog.MaxValue = files.Length;
                            dialog.Owner = this;
                            dialog.Show();
                            Task.Factory.StartNew(() =>
                            {
                                this.Invoke((MethodInvoker)(() =>
                                {
                                    windowTabControl.Enabled = false;
                                }));
                                foreach (var path in files)
                                {
                                    try
                                    {
                                        var folderName = Path.GetDirectoryName(path).Replace(srcPath, "");
                                        var directoryPath = GetSSFolderPath() + folderName;
                                        if (!Directory.Exists(directoryPath))
                                        {
                                            Directory.CreateDirectory(directoryPath);
                                        }
                                        File.Move(path, directoryPath + "\\" + Path.GetFileName(path));
                                    }
                                    catch
                                    {
                                    }
                                    dialog.Invoke((MethodInvoker)(() => ++ dialog.CurrentValue));
                                }
                                dialog.Invoke((MethodInvoker)(() => dialog.Close()));

                                this.Invoke((MethodInvoker)(() =>
                                {
                                    windowTabControl.Enabled = true;
                                    var lastImage = Directory.GetFiles(GetSSFolderPath(), "*.png", SearchOption.TopDirectoryOnly).OrderByDescending(n => File.GetLastWriteTime(n).Ticks).FirstOrDefault();
                                    if (settingsSortSS.Checked)
                                    {
                                        SortScreenshot(true);
                                    }
                                    else if (settingsUseCompress.Checked && lastCompressDate != DateTime.Now.Day)
                                    {
                                        CompressScrenshot();
                                    }
                                    else
                                    {
                                        fileListRefresher.RunWorkerAsync();
                                    }
                                    if (settingsStartWithMinimized.Checked)
                                    {
                                        WindowState = FormWindowState.Minimized;
                                    }
                                }));
                            });
                        }
                        else
                        {
                            if (settingsSortSS.Checked)
                            {
                                SortScreenshot(true);
                            }
                            else if (settingsUseCompress.Checked && lastCompressDate != DateTime.Now.Day)
                            {
                                CompressScrenshot();
                            }
                            else
                            {
                                fileListRefresher.RunWorkerAsync();
                            }
                            if (settingsStartWithMinimized.Checked)
                            {
                                WindowState = FormWindowState.Minimized;
                            }
                        }
                    }));
                });
            }
        }
예제 #2
0
        private void CompressScrenshot()
        {
            lastCompressDate = (byte)DateTime.Now.Day;
            LoadPreviewImage(null);
            LoadRecentlyImage(null);
            var files  = Directory.GetFiles(GetSSFolderPath(), "*.png", SearchOption.AllDirectories);
            var dialog = new ProgressWindow(metroStyleManager1);

            dialog.Title    = "スクリーンショット圧縮中...";
            dialog.MaxValue = files.Length;
            dialog.Owner    = this;
            dialog.Show();
            var bindmode   = settingsCompressMethod.SelectedIndex;
            var levelIndex = settingsCompressLevel.SelectedIndex;
            var level      = (CompressionLevel)levelIndex;

            Console.WriteLine(settingsCompressLevel.SelectedIndex);
            Console.WriteLine(level);
            Task.Factory.StartNew(() =>
            {
                this.Invoke((MethodInvoker)(() =>
                {
                    settingsUseCompress.Enabled = false;
                    windowTabControl.Enabled = false;
                }));
                ZipFile zip        = null;
                var currentZipFile = "";
                var limit          = settingsCompressDays.Value;
                long byteCount     = 0;
                var deletePath     = new List <string>();
                if (!Directory.Exists(GetSSFolderPath() + "\\Archives"))
                {
                    Directory.CreateDirectory(GetSSFolderPath() + "\\Archives");
                }
                foreach (var path in files)
                {
                    var info = new FileInfo(path);
                    var date = info.CreationTime;
                    if ((DateTime.Now - date).TotalDays >= limit)
                    {
                        var zipName = "";
                        if (bindmode == 0)
                        {
                            zipName = GetSSFolderPath() + "\\Archives\\" + string.Format("{0}-{1:D2}-{2:D2}_L{3}.zip", date.Year, date.Month, date.Day, levelIndex);
                        }
                        else if (bindmode == 1)
                        {
                            zipName = GetSSFolderPath() + "\\Archives\\" + string.Format("{0}-{1:D1}_L{2}.zip", date.Year, date.Month, levelIndex);
                        }
                        else
                        {
                            zipName = GetSSFolderPath() + "\\Archives\\" + string.Format("CompressedSS_L{0}.zip", levelIndex);
                        }
                        if (zip == null || zipName != currentZipFile)
                        {
                            if (zip != null)
                            {
                                zip.Save();
                                zip.Dispose();
                                zip = null;
                            }
                            zip = new ZipFile(zipName, Encoding.GetEncoding("shift_jis"));
                            zip.CompressionLevel = level;
                            currentZipFile       = zipName;
                        }
                        var entryName = Path.GetDirectoryName(path).Replace(GetSSFolderPath() + "\\", "");
                        try
                        {
                            zip.AddItem(path, entryName);
                            byteCount += info.Length;
                            if (byteCount > 104857600)
                            {
                                if (zip != null)
                                {
                                    zip.Save();
                                    zip.Dispose();
                                    zip = null;
                                }
                                byteCount = 0;
                            }
                            deletePath.Add(path);
                        }
                        catch
                        {
                        }
                    }
                    dialog.Invoke((MethodInvoker)(() => ++ dialog.CurrentValue));
                }
                if (zip != null)
                {
                    zip.Save();
                    zip.Dispose();
                    zip = null;
                }
                foreach (var v in deletePath)
                {
                    File.Delete(v);
                    var dir = Path.GetDirectoryName(v);
                    if (!Directory.EnumerateFileSystemEntries(dir).Any())
                    {
                        Directory.Delete(dir);
                    }
                }
                dialog.Invoke((MethodInvoker)(() => dialog.Close()));
                this.Invoke((MethodInvoker)(() =>
                {
                    settingsUseCompress.Enabled = true;
                    windowTabControl.Enabled = true;
                    LoadRecentlyImage(lastFilePath);
                    fileListRefresher.RunWorkerAsync();
                }));
            });
        }
예제 #3
0
        private void settingsFolderLinkSrc_FilePathChanged(object sender, EventArgs e)
        {
            if (finishInit)
            {
                CheckSSFolderIsExist();
                if (!IsSSFolderLinked())
                {
                    return;
                }
                newSSMoverWatcher.Path = settingsFolderLinkSrc.FilePath;
                fileSystemWatcher.Path = GetSSFolderPath();
                currentDirectory       = GetSSFolderPath();
                if (MessageBox.Show("元フォルダ内のファイルをリンク先へ移動しますか?", "確認", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    var srcPath  = settingsFolderLinkSrc.FilePath;
                    var destPath = settingsFolderLinkDest.FilePath;
                    LoadPreviewImage(null);
                    LoadRecentlyImage(null);
                    var files  = Directory.GetFiles(srcPath, "*.png", SearchOption.AllDirectories);
                    var dialog = new ProgressWindow(metroStyleManager1);
                    dialog.Title    = "スクリーンショット移動中...";
                    dialog.MaxValue = files.Length;
                    dialog.Owner    = this;
                    dialog.Show();
                    Task.Factory.StartNew(() =>
                    {
                        this.Invoke((MethodInvoker)(() =>
                        {
                            windowTabControl.Enabled = false;
                        }));
                        foreach (var path in files)
                        {
                            try
                            {
                                var folderName    = Path.GetDirectoryName(path).Replace(srcPath, "");
                                var directoryPath = GetSSFolderPath() + folderName;
                                if (!Directory.Exists(directoryPath))
                                {
                                    Directory.CreateDirectory(directoryPath);
                                }
                                File.Move(path, directoryPath + "\\" + Path.GetFileName(path));
                            }
                            catch
                            {
                            }
                            dialog.Invoke((MethodInvoker)(() => ++ dialog.CurrentValue));
                        }
                        dialog.Invoke((MethodInvoker)(() => dialog.Close()));

                        this.Invoke((MethodInvoker)(() =>
                        {
                            windowTabControl.Enabled = true;
                            var lastImage = Directory.GetFiles(GetSSFolderPath(), "*.png", SearchOption.TopDirectoryOnly).OrderByDescending(n => File.GetLastWriteTime(n).Ticks).FirstOrDefault();
                            LoadRecentlyImage(lastImage);
                            fileListRefresher.RunWorkerAsync();
                        }));
                    });
                }
                else
                {
                    var lastImage = Directory.GetFiles(GetSSFolderPath(), "*.png", SearchOption.TopDirectoryOnly).OrderByDescending(n => File.GetLastWriteTime(n).Ticks).FirstOrDefault();
                    LoadRecentlyImage(lastImage);
                    fileListRefresher.RunWorkerAsync();
                }
            }
        }