public static string toTimeMedia(this FileInfo file)
        {
            ShellFile so = ShellFile.FromFilePath(file.FullName);
            double nanoseconds;
            double.TryParse(so.Properties.System.Media.Duration.Value.ToString(), out nanoseconds);
            TimeSpan tmp = new TimeSpan();
            if (nanoseconds > 0)
            {
                double seconds = nanoseconds / 10000000;
                tmp = seconds.secondToTimeSpan();

            }
            return tmp.Format();
        }
Exemple #2
0
        public void MultipleConfigurationProgressHandler(object o, ProgressCallbackEventArgs progressArgs)
        {
            if (this.m_FormClosed)
            {
                // if form is closed we have no access to controls
                this.MasterInterpreter.Cancel();
                return;
            }

            this.m_stopwatch.Start();

            this.progressBarMultiple.Value = Math.Min((int)progressArgs.Percent, 100);

            if (progressArgs.Configuration == null)
            {
                this.lblMultiple.Text = string.Format("{0} - {1}", progressArgs.Context, progressArgs.Title);
            }
            else
            {
                this.lblMultiple.Text = string.Format("{0} - [{1}] - {2}", progressArgs.Context, progressArgs.Configuration, progressArgs.Title);
            }

            if (progressArgs.Percent == 0)
            {
                this.lblTimeEstimate.Text = "Calculating remaining time...";
            }
            else
            {
                TimeSpan remaining = new TimeSpan(this.m_stopwatch.Elapsed.Ticks * (long)((100 - progressArgs.Percent) / progressArgs.Percent));
                // TODO: make this label more user friendly
                this.lblTimeEstimate.Text = string.Format("Estimated remaining time: {0}.", remaining.Format());
            }

            if (progressArgs.Percent == 100)
            {
                if (this.IsDisposed == false)
                {
                    this.m_RaiseExceptionOnClose = false;
                    this.m_UserCancelled = false;
                    this.Close();
                }
            }
        }
        /// <summary>
        ///  Extracts all heightfields of the given map
        /// </summary>
        public static bool ExtractHeightfield(MapId mapId)
        {
            var name = TileIdentifier.GetName(mapId);
            if (string.IsNullOrEmpty(name))
            {
                Console.WriteLine(@"No ADT for map {0}.", mapId);
                return false;
            }

            // get started
            var mpqFinder = WCellTerrainSettings.GetDefaultMPQFinder();

            // Create WDT
            var wdt = new WDT(mapId);

            var startTime = DateTime.Now;

            // compute total size
            Console.Write(@"Estimating workload... ");
            var totalAmount = 0;
            var archives = new HashSet<string>();
            for (var tileX = 0; tileX < TerrainConstants.TilesPerMapSide; tileX++)
            {
                for (var tileY = 0; tileY < TerrainConstants.TilesPerMapSide; tileY++)
                {
                    var fname = ADTReader.GetFilename(mapId, tileX, tileY);
                    var archive = mpqFinder.GetArchive(fname);
                    if (archive != null && archive.GetFileSize(fname) > 0)
                    {
                        //totalSize += archive.GetFileSize(fname);
                        ++totalAmount;
                        archives.Add(archive.Path);
                    }
                }
            }
            Console.WriteLine(@"Done - Found {0} tiles in {1} files.", totalAmount, archives.Count);

            // Get cooking:
            Console.WriteLine();
            Console.WriteLine("Extracting...");

            // Load all ADTs and write them to file
            var processedTiles = 0;
            for (var tileX = 0; tileX < TerrainConstants.TilesPerMapSide; tileX++)
            {
                for (var tileY = 0; tileY < TerrainConstants.TilesPerMapSide; tileY++)
                {
                    try
                    {
                        var fname = ADTReader.GetFilename(mapId, tileX, tileY);
                        long fsize;
                        var archive = mpqFinder.GetArchive(fname);
                        if (archive != null && (fsize = archive.GetFileSize(fname)) > 0)
                        {
                            //processedSize += fsize;

                            var adt = ADTReader.ReadADT(wdt, tileX, tileY, false);
                            Console.Write(@"Tile ({0}, {1}) in Map {2} has been read from {3}. Writing... ",
                                tileX, tileY, mapId, Path.GetFileName(archive.Path));

                            // write to file
                            WriteHeightfield(adt);

                            // stats
                            ++processedTiles;
                            var timePassed = DateTime.Now - startTime;
                            var timePerTile = timePassed.Ticks / processedTiles;
                            var progress = processedTiles / (float)totalAmount;
                            var timeRemaining = new TimeSpan((totalAmount - processedTiles) * timePerTile);
                            Console.WriteLine(@"Done. [{0}/{1} {2:F2}% - {3} (Remaining: {4})]",
                                processedTiles,
                                totalAmount,
                                100 * progress,
                                timePassed.Format(),
                                timeRemaining.Format());
                            continue;
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine();
                        LogUtil.ErrorException(e, @"Extraction FAILED: Tile ({0}, {1}) in Map {2} could not be loaded", tileX, tileY, mapId);
                        return false;
                    }
                }
            }
            return true;
        }
Exemple #4
0
        private void drawScaleText(Graphics gc)
        {
            bool colHangOver = (LeftColumn > 0 && LeftColumn + DisplayedColumnCount > ColumnCount);
            int xLeft = colHangOver ? (ViewRectangle.Width - DisplayedColumnCount * _colWidth) : 0;

            double ticksPerInterval = _sched.TicksPerSec * _scaleInterval.TotalSeconds;
            int colLeft = (colHangOver ? LeftColumn - 1 : LeftColumn);
            int firstInterval = (int)Math.Ceiling(colLeft / ticksPerInterval);
            double pixPerInterval = ticksPerInterval * _colWidth;
            double xFirst = (pixPerInterval * firstInterval) - (colLeft * _colWidth);
            int nInterval = firstInterval;
            for (double x = xFirst + xLeft; x < ViewRectangle.Width; x += pixPerInterval, nInterval++)
            {
                TimeSpan interval = new TimeSpan(_scaleInterval.Ticks * (long)nInterval);
                gc.DrawString(interval.Format((int)_sched.TicksPerSec, _scaleFormat), _scaleFont, _scaleColor,
                    new RectangleF((int)x + 2, 2, _colWidth - 4, _scaleHeight - 4));
            }
        }