• Новые темы в этом разделе публикуются автоматически при добавлении файла в менеджер ресурсов.
    Ручное создание новых тем невозможно.
Иконка ресурса

Исходники updater/launcher и Patch Builder 2022-05-13

Нет прав для скачивания
. Похоже даже с ftp работает и zip разархивирует
 

C#:
        private void ThreadFunction(string fileName, string destName)
        {
            CompressFileLZMA(fileName, destName);
        }
        private void patchWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            var worker = sender as BackgroundWorker;
            string inputPath = inputFolderTb.Text.TrimEnd('\\');
            string outputPath = outputFolderTb.Text.TrimEnd('\\');
            // Clear old files if any inside output
            clearDirectory(outputPath);
            var patchFileWriter = new StreamWriter(outputPath + @"\patch.ini");
            try
            {
                var fileList = this.GetFiles(inputPath);
                int compressThreadCount = 6; // потоки сжатия
                Thread[] workerThreads = new Thread[compressThreadCount];
                var numbThreadFirstRun = 0;
                var totalFilesNumber = 0;
                var currentFileNumber = 0;
                foreach (string fileName in fileList)
                {
                    totalFilesNumber++;
                }
                foreach (string fileName in fileList)
                {
                    currentFileNumber++;
                    if (worker.CancellationPending == true)
                    {
                        e.Cancel = true;
                        break;
                    }
                    var hash = GetFileMD5Hash(fileName);
                    var relativePath = fileName.Replace(inputPath, "");
                    var remotePath = relativePath.Replace(@"\", "/") + ".7z";
                    patchFileWriter.Write(hash + "|" + relativePath + "|" + remotePath + ";");
                    _ = Invoke((MethodInvoker)delegate
                    {
                        outputLabel.Text = currentFileNumber + " / " + totalFilesNumber + " - Processing " + relativePath.TrimStart('\\');
                    });
                    // пока не создать потоки впервые, workerThreads[i].IsAlive выдает null
                    if (numbThreadFirstRun < compressThreadCount)
                    {
                        workerThreads[numbThreadFirstRun] = new Thread(() => ThreadFunction(fileName, fileName.Replace(inputPath, outputPath) + ".7z"));
                        workerThreads[numbThreadFirstRun].Start();
                        numbThreadFirstRun++;
                    }
                    else
                    {
                        var taskInThread = 0;
                        while (taskInThread == 0)
                        {
                            for (int i = 0; i < compressThreadCount; i++)
                            {
                                if (workerThreads[i].IsAlive == false && taskInThread == 0)
                                {
                                    workerThreads[i] = new Thread(() => ThreadFunction(fileName, fileName.Replace(inputPath, outputPath) + ".7z"));
                                    workerThreads[i].Start();
                                    taskInThread = 1;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                    }
                }
                patchFileWriter.Close();
                // ожидаем потоки
                var endThreadsCheck = compressThreadCount;
                while (endThreadsCheck != 0)
                {
                    endThreadsCheck = compressThreadCount;
                    for (int i = 0; i < compressThreadCount; i++)
                    {
                        if (workerThreads[i].IsAlive == false)
                        {
                            endThreadsCheck = endThreadsCheck - 1;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }

                
            }
            catch (Exception ex)
            {
                patchFileWriter.Close();
                throw ex;
            }
        }

потоки добавил, а вот мозгов сделать интерфейсные кнопки нет..
compressThreadCount неплохо бы вывести как переключатель 1-32
 
Назад
Сверху Снизу