示例#1
0
文件: Program.cs 项目: jlovenpk1/LOJ
        static void Main(string[] Args)
        {
            //MessageBox.Show("Точка входа");

            {
                var S = System.Diagnostics.Process.GetProcessesByName(Application.ProductName);

                if (S.Length > 1)
                {
                    var CurrPID = System.Diagnostics.Process.GetCurrentProcess().Id;

                    if (MessageBox.Show("Программа уще запущена\nЗакрыть ту, что была запущена раньше?\nВ противном случае запуск этой копии будет прерван.", "Внимание", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                    {
                        for (int i = 0; i < S.Length; i++)
                        {
                            if (S[i].Id != CurrPID)
                            {
                                S[i].Kill();
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < S.Length; i++)
                        {
                            if (S[i].Id != CurrPID)
                            {
                                SetForegroundWindow(S[i].MainWindowHandle);
                                break;
                            }
                        }
                        Application.ExitThread();
                        return;
                    }
                }
            }

            var m = new List <string>(3);

            if (!System.IO.File.Exists(Application.StartupPath + "\\MySql.Data.dll"))
            {
                m.Add("MySql.Data.dll");
            }

            if (!System.IO.File.Exists(Application.StartupPath + "\\NPOI.dll"))
            {
                m.Add("NPOI.dll");
            }

            if (!System.IO.File.Exists(Application.StartupPath + "\\AutoTable.dll"))
            {
                m.Add("AutoTable.dll");
            }

            if (m.Count > 0)
            {
                var message = "";
                for (int i = 0; i < m.Count; i++)
                {
                    if (m[i] != null)
                    {
                        message += '\n' + (i + 1).ToString() + ")" + m[i];
                    }
                    else
                    {
                        break;
                    }
                }

                MessageBox.Show("Похоже, что отсутсвуют некоторые компоненты программы:" + message + "\nЧтобы устранить проблему обратитесь в отдел ИТиТ");
                return;
            }

            Application.SetCompatibleTextRenderingDefault(false);

            SetArgs(Args);

            if (File.Exists(Application.StartupPath + "\\commands.txt"))
            {
                using (var sr = new StreamReader(Application.StartupPath + "\\commands.txt"))
                {
                    var FArgs = new List <string>();

                    while (!sr.EndOfStream)
                    {
                        FArgs.Add(sr.ReadLine());
                    }

                    SetArgs(FArgs.ToArray());
                }
            }

            if (data.DeleteConf && File.Exists(Application.StartupPath + "\\commands.txt"))
            {
                File.Delete(Application.StartupPath + "\\commands.txt");
            }

            AutoUpdate.UpdateAutoUpdate(data.StName, null);

            Misc.Prepare();  //гружу настройки

            var form = new Startup_Form();

            if (!form.IsDisposed)
            {
                Application.EnableVisualStyles();
                Application.Run(form);
            }
        }
示例#2
0
文件: DB_Form.cs 项目: jlovenpk1/LOJ
            protected override bool Do()
            {
                var CurrentCount = 0;
                var MaxCount     = 101;

                try
                {
                    string savepath;
                    var    SevenPack = new SevenZipCompressor();

                    SevenPack.CompressionLevel        = CompressionLevel.Ultra;
                    SevenPack.IncludeEmptyDirectories = false;

                    SevenZip.SevenZipCompressor.SetLibraryPath(
                        Path.Combine(
                            Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
                            AutoUpdate.Get7zdllName()));

                    var DT = DateTime.Now;

                    var allDrives = DriveInfo.GetDrives();

                    for (int i = 0; i < allDrives.Length; i++)
                    {
                        if (allDrives[i].DriveType == DriveType.Fixed && allDrives[i].TotalFreeSpace > (10 * 1024 * 1024))
                        {
                            savepath = allDrives[i].RootDirectory.Name + "dmp\\loj";

                            if (!Directory.Exists(savepath))
                            {
                                Directory.CreateDirectory(savepath);
                            }

                            goto ItsOk;
                        }
                    }

                    Action("Нет свободного места", MaxCount, MaxCount);
                    return(false);

                    ItsOk :;

                    SevenPack.Compressing += (percentDone, percentDelta) =>
                    {
                        CurrentCount = percentDelta.PercentDone;
                        Action("Архивирование " + percentDelta.PercentDone.ToString() + " из " + 100, MaxCount, CurrentCount);
                    };

                    FileName = savepath + "\\" + data.User <string>(C.User.Login) + ' ' + data.User <string>(C.User.PCName) + ' ' + DT.Day.ToString() + "." + DT.Month.ToString() + "." + DT.Year.ToString() + ' ' + DT.Hour.ToString() + "." + DT.Minute.ToString() + "." + DT.Second.ToString() + ".7z";

                    SevenPack.CompressDirectory(Application.StartupPath, FileName);

                    Action("Отправка", MaxCount, CurrentCount++);

                    var From       = new MailAddress(data.PrgSettings.Values[(int)data.Strings.MailLogin].String, "Me");
                    var To         = new MailAddress(data.PrgSettings.Values[(int)data.Strings.MailLogin].String, "Me");
                    var NewMessage = new MailMessage(From, To);
                    NewMessage.Subject = "dmp";
                    NewMessage.Attachments.Add(new Attachment(FileName));
                    Smtp.Send(NewMessage);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(false);
                }

                Action("Готово", MaxCount, CurrentCount++);

                return(true);
            }